Q: Display current logged-in user I'm using Symfony and sfDoctrineGuardPlugin.
How do I display, in a template, the username of the current user ?
I've tried $this->getUser()->getUsername(), but all I get is the error : "Call to undefined method sfPHPView::getUser."
I'm trying to display the username in a layout.php, not in a particular module/template

A: In a template (view), use $sf_user:
For the username:
echo $sf_user->getUsername();

For the id:
echo $sf_user->getAttribute('user_id', null, 'sfGuardSecurityUser');

Or, in an action (controller), you can do what you're doing in your question:
$this->username = $this->getUser()->getUsername();

and then $username will be available in your view template.
See template shortcuts in the Symfony docs for other view variable shortcuts.

A: Try the following. One of them may work.
$this->getSfGuardUser()
$this->getGuardUser()
$this->getUser()->getSfGuardUser()
$this->getUser()->getGuardUser()

