【发布时间】:2014-03-03 15:35:57
【问题描述】:
我的模型中有一个使用连接的查询并将查询结果作为数组返回
result_array();
然后我将该结果返回给我调用模型的控制器。
$data = $this->Model->show();
foreach($data as $val)
{
$arr[$val['recipename']] = $val['componentname'];
}
if($data != null)
{
$this->load->view('Admin\success',$arr);
}
我最初没有 $arr 值。我只是将它添加到那里以使数组更清晰。无论如何,有或没有。
var_dump($data) 和 var_dump($arr) 或者即使我 $recipename 或 $componentname 仍然为空。
返回空值。说它们是未定义的。
我不知道出了什么问题。
我读了另一个问题。这就是为什么我制作了 $arr 以便我可以将其设为单个数组,因此当它传输时,它将被提取并尝试回显它们但无济于事。
Codeigniter passing data from controller to view
编辑:
查询工作正常,它返回值。
$sample = $this->db->select('recipe.recipename,component.componentname')->from('recipe')
->join('recipecomponent','recipe.recipeid = recipecomponent.recipeid')
->join('component','component.componentid = recipecomponent.componentid')
->group_by('recipe.recipeid')
->get()
->result_array();
return $sample;
【问题讨论】:
-
您检查过
$this->Model->show();是否返回任何内容吗? -
可能不应该使用名为 model 的模型。
-
$arr 在 if 语句中超出范围 - 除非您已在此代码之外声明它
-
为了简单起见,我只使用了模型名称,因为它在我的代码上有所不同,是的,我在每个操作通过 $this->load->view 之前使用了 print_r() 并且它们具有值。它在视图传递后唯一的 null。
标签: php codeigniter