The controller is for calculating and manipulating data and passing the results to the view, and the view takes the results and render them to HTML.
If you should use if
statement in the view to show or hide some markup, you are allowed!
but if the changing section contains a lot of information, I suggest using partial views and passing their content as a variable to the main view. And doing all these in controller.
To do that in CodeIgniter:
Controller:
class Foo extends CI_Controller {
public function bar()
{
// prevent getting error.
$data['partial'] = '';
// check if user is logged in.
if ($this->session->userdata('user_id') == TRUE) {
$data['partial'] = $this->load->view('partial/baz', '', TRUE);
} else {
$data['partial'] = $this->load->view('partial/qux', '', TRUE);
}
$this->load->view('my_view', $data);
}
}
Assumption: user_id
is set in CI session when user log in.
View:
<?php echo $partial; ?>