php - Getting user data -
there 2 parts application i've been building. there's website powered cms , there's cms (wrestling manager) goes it. 2 controllers created called frontend , backend use accordingly. frontend controller responsible code needs ran across controllers on website. backend controller responsible code needs ran across controllers on cms.
i'm looking ideal way work user data after user logs in again gets directed dashboard extended backend controller. i've heard different solutions example hook. that's 1 i've heard.
inheritance friend here
you create master controller(front-controller) extends ci_controller
you might consider doing spa application, if there many great frameworks achieve this, quite popular 1 angular.js
some more useful reading on subject...
class my_controller extends ci_controller { protected $currentuser; protected $template; public function __construct() { //you talked hooks //this constructor same saying //post_controller_constructor $this->template = 'master/default'; } //ok functions need run //throughout application //run them once here, keeping our app dry protected function isajax() { return ($this->input->is_ajax_request()) ? true : show_error('invalid request!'); } protected function isloggedin() { //load auth library maybe here $this->load->library('auth'); //check have "current logged in user" //expect object or null/false $this->currentuser = $this->auth->getloggedinuser(); return ($this->currentuser) ?: false; } } class frontend_controller extends my_controller { public function __construct() { parent::__construct(); } public function testfirst() { //maybe need test ajax request here //inheritance parent $this->isajax(); } public function testsecond() { //maybe need user logged in here //inheritance parent $this->isajax(); //or yet again, abstract parent level if(!$this->currentuser || is_null($this->currentuser)) { //handle errors on frontend return $this->output->set_status_header(401); //un-authorized } } }
Comments
Post a Comment