»
S
I
D
E
B
A
R
«
2 Codeigniter Controller Querys on One View
November 11th, 2009 by wood

How do you put two different function outputs from the same controller into the same view(page)? For example, I have a function going to the "article" div, and another function that I am trying to use within the "aside" div. (using HTML 5 nomenclature here)

I have went as far as using the actual db query in the (view)aside div and it still only displays the 1st article function.

I have changed the $data('result') variable to separate variables and that makes no difference.

I am showing a todo list of jobs I have to do in the article div, then showing the titles of the completed todo's in the aside div.

I suppose I am making a mess of this explanation. Would you use a function from a different controller?


2 Responses  
  • michaeljdennis writes:
    November 12th, 2009 at 2:58 am

    Here’s a simple example that might help:

    CONTROLLER:

    function index()
    {
    $data['to_dos'] = $this->db->get(’to_dos’);
    $data['completed_to_dos'] = $this->db->get(’completed_to_dos’);
    $this->load->view(’to_do_view’);
    }

    VIEW:

    openphptag

    foreach($to_dos as $to_do)
    {
    echo $to_do,”;
    }

    closephptag

    openphptag

    foreach($completed_to_dos as $completed_to_do)
    {
    echo $completed_to_do,”;
    }

    closephptag

  • Jason writes:
    November 25th, 2009 at 3:30 pm

    $data(’result’) is not an array. When you call $this->load->view(’view_file_name’, $data_array) $data_array should contain your associative array.

    From your example it appears you forgot to pass the second parameter to the view method ($this->load->view).


Leave a Reply

»  Substance: PHP Frameworks   »  SiteMap