Ghostman
Ghostman

Reputation: 6114

Two views for one controller codeigniter

How to use two views in one controller in codeigniter

function index()
{
    $data['title'] =" Details";                      
    $data['courses']=$this->coursemodel->getcourse();
    $data['batches']=$this->coursemodel->getbatchname();
    $this->load->view('admin/fees/coursereport',$data);                      
}

first view

      $this->load->view('admin/fees/coursedetails',$data);

second view

       $this->load->view('admin/fees/coursereport',$data);

My question is how to use two views in one controller in codeigniter

Upvotes: 1

Views: 3579

Answers (1)

ariefbayu
ariefbayu

Reputation: 21979

Use third parameter of view() and insert the result to another string. Finally, print that string as you like:

$FinalOutput = "";
$FinalOutput .= $this->load->view('admin/fees/coursedetails',$data, true);
$FinalOutput .= $this->load->view('admin/fees/coursereport',$data, true);

Finally, at the end of your script:

$this->load->view('admin/fees/template',array('output' => $FinalOutput));

UPDATE

I see that you updated your question. If the above is not what you looking for, maybe this is:

if( $data['title'] == 'Detail')
    $this->load->view('admin/fees/coursedetails',$data);
else
    $this->load->view('admin/fees/coursereport',$data);

The idea here is, by checking what view you really want. Is it what you needed?

Upvotes: 2

Related Questions