[英]CodeIgniter: Passing information from the Model to the Controller using result_array()
I have the following model that print_r
shows Array ( [id] => 1 [cms_name] => Content Mangement System )
Currently in my controller I have $data['contentMangement'] = $this->model->function
but I am unsure how to bring my above array into this. 我有以下模型,
print_r
显示了Array ( [id] => 1 [cms_name] => Content Mangement System )
当前在我的控制器中,我有$data['contentMangement'] = $this->model->function
但我是不确定如何将我上面的数组放入其中。
function systemOptions($options)
{
$this->db->select($options);
$query = $this->db->get('options');
if($query->num_rows() > 0)
{
$row = $query->row_array();
$row['cms_name'];
}
print_r($row);
return $query->result_array();
}
If you want all of your options you can do this: 如果需要所有选项,可以执行以下操作:
function systemOptions($options)
{
$this->db->select($options);
return $this->db->get('options')->result_array();// will return empty array if there are no results
}
Or if you just want the first row (which is what it looks like from your question) you can do this: 或者,如果您只想要第一行(这就是您的问题的样子),则可以执行以下操作:
function systemOptions($options)
{
$this->db->select($options);
$result = $this->db->get('options')->result_array();
if(!empty($result))
{
return $result[0];
}else{
return null; //or false or array(), or whatever you want
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.