0

如果来自先前加载的模型请求的数据是_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']);

    }
4

1 回答 1

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']);

}

或者

$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']);

}
于 2013-07-13T16:04:59.740 回答