簡體   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