I have a few pages that require login, so all controllers that link to these pages start with
$this->checkSession(); //...rest of the code
In this case you should not use exit, what you should do if the session is not valid is redirect your app using example:
redirect('/init/login/','refresh');
Put the code in a variable and write it.
$html = $this->load->view('template',null,true); echo $html; exit();