Strictly speaking, $this->session->userdata['user_id'] belongs to the controller.
Models deal only with data ... controllers, by definition, control the flow of data ...
and authentication is a form of data management ... (IMHO)
In code, I follow this procedure
class MyControllerName extends Controller{ function MyMyControllerName(){ parent::Controller(); $this->_user_id=$this->session->userdata['user_id'];
And then, say, one of my foo() functions requires authentication .. I would do this
function foo(){ $this->_checkAuthentication();
_checkAuthentication() can be simplified, for example:
function _checkAuthentication(){ if(!isset($this->_user_id) && $this->_user_id<=0){ /or any other checks header("Location: ".base_url()."location_of/user_not_authorised_page"); exit; } }
source share