我即将在我的 codeigniter 项目中实现解析器类,并希望在将数据从我的模型传递到解析器数组时获得一些指导。哪种方法更好更有效。
我的模型获取数据并将其返回给 Controller 。我怎样才能把它放到 Controller 的数组中?
型号:
function getSeo($data){
$this->db->select('seo_title, seo_description, seo_keywords');
$this->db->from('content');
$this->db->where($data);
$query = $this->db->get();
$data = array();
foreach ($query->result() as $row) {
$data[] = array(
'seo_title' => $row->seo_title,
'seo_description' => $row->seo_description,
'seo_keywords' => $row->seo_keywords
);
}
return $data;
}
Controller :
$viewdata['pageseo'] = $this->Content_model->getSeo($data);
$viewdata = array(
'seo_title' => 'My seo Title',
'seo_description' => 'My seo description',
'seo_keywords' => 'My seo keywords',
);
从我的模型中获取数据到“$viewdata”数组的最佳方法是什么,它是如何完成的????
最佳答案
由于模型中的 getSeo 函数返回一个数组,因此 Controller 也会将此信息存储到您的 $viewdata 数组中。
如果您尝试使用 print_r($viewdata)
,您会发现结构符合预期。这是 $viewdata['seo_title'] => 'My seo Title'
等等……
关于php - Codeigniter 将数据从模型传递到 Controller 解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8007110/