Change CakePHP default routing after login

Reading time ~1 minute

This is coming directly from here. That website is out of date, and so here it is, v2.0 fresh.
I am assuming you understand routes.

In your bootstrap.php file add the following. This will instantiate CakeSession (after it's inclusion), from there you can check the status of the login and define the routes based on whether the user is logged in or not.

<?
// include the Session Component to our application
App::uses('CakeSession', 'Model/Datasource');
// now create new SessionComponent instance
$Session = new CakeSession();
// check if the user logged in
if ($Session->read('Auth.User')) {
    // set the default routing to submissions controller
    Configure::write('Route.default', array('controller' => 'users', 'action' => 'index'));
}
// nope, user not logged in
else {
    // set the default routing to our login page in users controller
    Configure::write('Route.default', array('controller' => 'pages', 'action' => 'display', 'home'));
}
and make sure this is in your routes.php file. Comment out or remove the old line.
<?
Router::connect('/', Configure::read('Route.default'));

Quick Laravel/Lumen install with Docker!

The default installer that comes with Laravel is great, but unfortunately that means you have to install dependencies of PHP and Laravel/...… Continue reading

PHP To Python

Published on February 24, 2016

Aftertouch in Logic Pro X and 2015 Macbook Pro

Published on February 24, 2016