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
    }
}