1

これは私のAppControllerです:

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
                        )

                )

        )

)

私のユーザーには、名前、電子メール、およびその他のデータがあります。このデータにアクセスできないのはなぜですか?

4

3 に答える 3

0

AuthコンポーネントがAppControllerにロードされていることを確認してください

App::uses('AuthComponent', 'Controller/Component');
于 2014-02-11T15:57:07.460 に答える