CakePHP 3.x - AuthComponent::user() in View

wildfireheart picture wildfireheart · Dec 19, 2014 · Viewed 16.5k times · Source

In CakePHP 2.x you could do

 AuthComponent::user()

in View to get data from Auth component. In CakePHP 3.0beta3 it throws:

 "Error: Class 'AuthComponent' not found"

Is there a simple way to get data from AuthComponent in View?

Answer

mario741 picture mario741 · Apr 4, 2016

In View:

$this->request->session()->read('Auth.User.username');

In Controller

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