Reputation: 16278
I want to create a navigation bar similar to the one here in StackOverflow or the one in most social networks, where it shows the user information (name, profile pic) or if there is no logged user then it shows a log in button.
I read this kind of view are supposed to be implemented as element using $this>element('name');
inside a view. The thing is that I don't know how to get the user information within the element. How can I do this?
Upvotes: 1
Views: 502
Reputation: 54771
In your controller assign the user's current information to a view variable.
public function index()
{
$user = <-- assign current user info
$this->set('user',$user);
}
In your index.ctp
view file pass that information to the element to be rendered.
echo $this->element('user_info',array('myvar'=>$user));
In your user_info.ctp
element file display the user information.
echo $myvar['email'];
Upvotes: 3