I am making a users profile page and if i route it like this
Router::connect('/users/profile', array('controller' => 'users', 'action' => 'profile'));
then $this->Auth->user() work fine in UsersController->profile() but if iroute it like this
Router::connect('/pages/profile', array('controller' => 'pages', 'action' => 'profile'));
then it doesnt in PagesCotroller->profile() the profile function is the same in both cases
my app controller:
class AppController extends Controller {
var $components = array(
'Auth' ,
'Acl',
'Session',
'Cookie'
);
var $userdata = array();
function beforeFilter(){
$this->Auth->userModel = 'Users';
$this->Auth->loginRedirect = array();
$this->Auth->allow('display');
$this->Auth->allow('index');
var_dump($this->Auth->user());
parent::beforeFilter();
}
function isAuthorized() {
return true;
}
}
and var_dump actually works if i go to /users/profile and doesnt if i go to /pages/profile
without any additional logging in or anything
$this->Auth->allow() works properly in both controllers by the way, so Auth component is available in both
here’s pagescontroller
class PagesController extends AppController {
var $components = array('RequestHandler');
var $name = 'Pages';
var $helpers = array('Html', 'Session','Form','Ajax', 'Jquery');
var $uses = array('Users');
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('profile');
}
function beforeRender() {
parent::beforeRender();
}
function profile(){
var_dump($this->Auth->user());
}
}
I found the answer it was captcha component. It started session every time it was called and it wass called from all the controllers except users. So the user log in data was not preserved.