繁体   English   中英

CodeIgniter:使用result_array()将信息从模型传递到控制器

[英]CodeIgniter: Passing information from the Model to the Controller using result_array()

我有以下模型, 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();
    }

如果需要所有选项,可以执行以下操作:

function systemOptions($options)
{   
    $this->db->select($options);

    return $this->db->get('options')->result_array();// will return empty array if there are no results

}

或者,如果您只想要第一行(这就是您的问题的样子),则可以执行以下操作:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM