开发者

CodeIgniter view problem

This is my first day playing with CI and I really like it so far but have a problem I can't solve on my own. The issue is that I need to generate single view with two controller functions. One div should include selected row by ID from table A and other div should loop foreach on array from table B.

    public function index()//div A
{
            $data['query'] = $this->db->get_where('beer', array('id' => 1)开发者_运维问答);
    $this->load->view('corp/corp_view', $data);     
}

public function loadList() //div B
{
    $data['q'] = $this->db->get_where('list', array('id' => 1));
    $this->load->view('corp/mentor_list_view', $data);
}   

I tried to solve this for few hours by creating another view for loadList() and then including it in the the main view like "$this->load->view()" but I'm getting the values from the index() function query table 'beer' not 'list' table as intended. Again I'm new to this and would appreciate your help.

Thank you for your help.


Thanks for the extra info, i can help yah out now.

In Codeigniter if you want to make a function that is not able to be called by the user just precede it with a '_'. So in your case:

public function index()//div A
{
    $data['query'] = $this->db->get_where('beer', array('id' => 1));
    $data['query2'] = $this->_mySecondQuery();
    $this->load->view('corp/corp_view', $data);     
}

public function _mySecondQuery() //div B
{
    return $this->db->get_where('list', array('id' => 1));
}

Now in the index page you have access to both queries. Btw, I would not suggest doing much DB work in the controller. DB work is meant to be done in Models. For more info on those see: Codeigniter Models

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜