这是我的应用控制器:
class AppController extends Controller {
public $components = array('Auth');
public function beforeFilter() {
//Set up Auth Component
$this->Auth->userModel = 'CmsUser';
$this->Auth->authenticate ='Form';
$this->Auth->fields = array('username' => 'username', 'password' => 'password');
$this->Auth->loginAction = array('controller' => 'admin_cms_users', 'action' => 'login','admin' => true);
$this->Auth->loginRedirect = array('controller' => 'admin_cms_helps', 'action' => 'index');
$this->Auth->logoutRedirect = '/';
$this->Auth->loginError = 'Pogrešno korisničko ime/lozinka. Pokušajte ponovo!';
$this->Auth->autoRedirect = false; // najvažnija postavka za redirekciju
$this->Auth->allow('display');
// Additional criteria for loging.
$this->Auth->userScope = array('CmsUser.active' => 1); //user needs to be active.
}
这是我的 AdminCmsUsersController:
class AdminCmsUsersController extends AppController {
public $name = 'AdminCmsUsers';
public $uses = array('CmsUser');
public function beforeFilter(){
parent::beforeFilter();
}
.
.
.
.
public function admin_login() {
$this->layout='cms_main';
if($this->request->is('post') AND $this->Auth->login($this->request->data)){
$this->CmsUser->id = $this->Auth->user('id');
print_r($this->Auth->user());
print_r($this->Session->read());
$this->redirect($this->Auth->redirect());
}
}
.
.
.
print_r($this->Auth->user()) 结果:
Array
(
[CmsUser] => Array
(
[username] => someuser
[password] => somepass
)
)
//print_r($this->Session->read()) 结果:
[Auth] => Array
(
[User] => Array
(
[CmsUser] => Array
(
[username] => lupus10
[password] => canis10
)
)
)
)
我的用户有姓名、电子邮件和其他数据。为什么不能访问这些数据?