Issue
I work on CakePHP 3 project. I want to display username of the logged user from default.ctp so I tried this:
//in default.ctp
$user = $this->Session->read('Auth.User');
if(!empty($user)) {
echo 'Hi ', $user['user_name'];
}
It doesn't work and I found other solution which tells me to put the current user in session from AppController it doesn't work either.
// in AppController
function beforeFilter(){
$user = $this->Session->read('Auth.User');
$this->set('username', $user['username']);
}
and in default.ctp:
<?=$username?>
How can I make this work?
Solution
<?php $session = $this->request->session(); // less than 3.5
// $session = $this->request->getSession(); // 3.5 or more
$user_data = $session->read('Auth.User');
if(!empty($user_data)){
print_r($user_data);
}?>
try this hope it help's..
Answered By - Vivek Singh
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.