model view controller - Most efficient way to implement a 'logged-in' check with MVC in PHP? -
i know questions similar have been asked, have been searching through internet , can't seem find i'm looking for.
the common answer put in controller. liked particular solution stackoverflow had sessioncontroller
, nonsessioncontroller
, both extending main controller sessioncontroller
checking if user logged in before dispatch.
does mean controller this?
class sessioncontroller { ... function view() { //view thread stuff } function post() { if loggedin { //post thread stuff } } {
in situation, looks nonsessioncontroller
useless, , model used when every action controller handles either strictly users or non-users, unlike forum example.
so guess question is, general concept of controller above efficient way of dealing login checks when using mvc?
i think idea have 1 controller checks session , login, , 1 doesn't.
i put login check in constructor of session controller way every controller extends check login.
the session controller like
class sessioncontroller { public function __construct() { if ( ! authenticationhelper::isloggedin() ) { // user not logged in // something, maybe redirect login page } } }
then can extend controller like
class homecontroller extends sessioncontroller { public function __construct() { parent::__construct(); } public function index() { print "this page checks login status"; } }
Comments
Post a Comment