简体   繁体   中英

cake php passing the current logged in user array

cakephp is amazing but this auth stuff i haven't gotten all the pieces, my question is simple. I want to pass the current logged in users array data so i can use it in a view. I use animal names as my testing names

class UsersController extends AppController {

     public function cat() {
        $this->set('cat',$this->Auth->login($this->request->data) );
            //I also tried $this->Auth->login()
    }
}

now my view //cat.ctp

<div>
<?php echo print_r($cat)?> //returns 11
</div>

或者,您可以通过会话帮助器在视图文件中访问用户信息:

<?php print_r($this->Session->read('Auth.User')); ?>

在您的控制器中,$ this-> Auth-> user()将返回一个包含当前用户数据的数组。

You can retrieve authentified user's data from the controller using

$this->Auth->user();
exp: $this->Auth->user('username');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM