Codeigniter从模型加载数据的最佳方法

时间:2013-07-13 15:48:10

标签: codeigniter

如果来自先前加载的模型请求的数据是numeric,我试图从模型加载数据。我已经编写了这样的代码,虽然它不起作用,我有点理解。但我不知道如何从数据['schedule_item']获取内容。

    $this->load->model('schedule_model');
    $this->load->model('partners_model');
    $data['schedule_item'] = $this->schedule_model->getAll();

    if(is_numeric($schedule_item['featured_partner1']) {

    $data['featured_partner1'] = $this->schedule_model->get_partner($schedule_item['featured_partner1']);

    }

1 个答案:

答案 0 :(得分:0)

您获取的错误变量已将$data数组的索引上的模型值分配给$schedule_item,因此未定义$schedule_item只有在所有$data的索引将转换为您应尝试执行此操作的变量,如

$this->load->model('schedule_model');
$this->load->model('partners_model');
$schedule_item=$this->schedule_model->getAll();
$data['schedule_item'] =$schedule_item;
if(is_numeric($schedule_item['featured_partner1']) {

$data['featured_partner1'] = $this->schedule_model->get_partner($schedule_item['featured_partner1']);

}

OR

$this->load->model('schedule_model');
$this->load->model('partners_model');
$data['schedule_item'] =$this->schedule_model->getAll();
if(is_numeric( $data['schedule_item']['featured_partner1']) {

$data['featured_partner1'] = $this->schedule_model->get_partner($schedule_item['featured_partner1']);

}