将codeigniter $ data [' foo']从控制器传递到视图

时间:2014-08-11 16:38:40

标签: php codeigniter

我有这段代码

 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 个答案:

答案 0 :(得分: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); }