Reputation: 16278
The navigation bar in my application will contain User
information (name, profile pic), and some associated data. Since the navigation bar is going to be present in the whole application, I'm putting my logic inside AppController::beforeRender()
in order to pass data to the View
(in this case, the Element nav_bar).
Which of the followings is the correct way to load User
model data.
public function beforeRender() {
$this->loadModel('User'); // this one
$this->User->find(...
ClassRegistry::init('User')->find(... // Or this one?
Upvotes: 0
Views: 346
Reputation: 1774
In your view, Use the AuthComponent class to access to the user information, for example :
to havethe id of user : $use_id = AuthComponent::user('id');
to have all the informations of user : $user = AuthComponent::user();
Upvotes: -1
Reputation: 3889
I would save the user information in a Session, otherwise you will be hitting the database in every single request.
So, what you wanna do is: in your login() function you get the user information and save it in a Session. Then, in your element, you simply echo the content you want from your Session.
Upvotes: 2