Would someone pease explain this function to me in its entirety? i.e what the function beforeFilter does and what each line is doing. Thanks.
function beforeFilter()
{
//Configure AuthComponent
$this->Auth->authorize = 'actions';
$this->Auth->actionPath = 'controllers/';
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'add');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
}
Documented Code
// `beforeFilter()` gets executed before the request forwarded to `action`
function beforeFilter() {
//Configure AuthComponent
// read http://book.cakephp.org/complete/1250/Authentication#authorize-1275
$this->Auth->authorize = 'actions';
// read http://book.cakephp.org/complete/1250/Authentication#actionPath-1279
$this->Auth->actionPath = 'controllers/';
// tells the Auth component the location of login action
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
// tells the Auth component where to redirect after successful login
$this->Auth->loginRedirect = array('controller' => 'posts', 'action' => 'add');
// tells the Auth component where to redirect after logout
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); }
Your must read this http://book.cakephp.org/complete/1250/Authentication