将 codeigniter $data['foo'] 从控制器传递给视图
Posted
技术标签:
【中文标题】将 codeigniter $data[\'foo\'] 从控制器传递给视图【英文标题】:Pass codeigniter $data['foo'] from controller to view将 codeigniter $data['foo'] 从控制器传递给视图 【发布时间】:2014-08-11 16:38:39 【问题描述】:我有这个代码
public function delete($delete_candindate)
$this->load->database();
$this->load->dbforge();
$delete_candindate = $this->uri->segment(3);
$this->dbforge->drop_table($delete_candindate);
$this->db->where('dataset_name', $delete_candindate);
$this->db->delete('all_datasets');
$data['success_or_failure'] = 'That dataset already exists.Kindly go back and try again.';
$this->load->view('success_or_failure');
我用来从我的表中删除一些数据,但我现在需要将数据从控制器传递到视图,但我的控制器有一个参数。
不知何故,变量$data['success_or_failure']
没有被传递,因为我不断收到此错误
遇到了 php 错误
严重性:通知
消息:未定义变量:success_or_failure
文件名:views/success_or_failure.php
行号:54
为什么不将$data['success_or_failure'] = 'That dataset already exists.Kindly go back and try again.';
传递给视图?
【问题讨论】:
【参考方案1】:发现我没有传递$data
变量
public function delete($delete_candindate)
$this->load->database();
$this->load->dbforge();
$delete_candindate = $this->uri->segment(3);
$this->dbforge->drop_table($delete_candindate);
$this->db->where('dataset_name', $delete_candindate);
$this->db->delete('all_datasets');
$data['success_or_failure'] = 'That dataset already exists.Kindly go back and try again.';
$this->load->view('success_or_failure',$data);
【讨论】:
以上是关于将 codeigniter $data['foo'] 从控制器传递给视图的主要内容,如果未能解决你的问题,请参考以下文章