Nll
Nll

Reputation: 878

$sf_user->getGuardUser() doesn't work

I'm developing a project using sf1.4, i put this code in a template :

<p class="welcome"><?php echo $sf_user->getGuardUser()->getProfile()->getFirstName().' '.$sf_user->getGuardUser()->getProfile()->getLastName()?></p>
<p class="logout"><a href="<?php echo url_for("@sf_guard_signout"); ?>
">Log Out</a></p>

Then$sf_user->getGuardUser()seems not work when I click Logout, and I have this error :

 Fatal error: Call to a member function getProfile() on a non-object in...on line 3

Edit :

In apps/myapp/config/app.yml, I add :

all:
  sf_guard_plugin:
    profile_class:      sfGuardUserProfile
    profile_field_name: user_id

Edit 2 :

I find that this code works very fine is same templates and it give me an error in others!

Upvotes: 0

Views: 372

Answers (1)

antony
antony

Reputation: 2893

If you look at the getProfile() method of the sfGuardUser object, you'll see it checks your app.yml file for a default Profile class:

$profileClass = sfConfig::get('app_sf_guard_plugin_profile_class', 'defaultClassName');

So make sure yo uhave this information in your app.yml

// apps\myApp\config\app.yml
sf_guard_plugin:
   profile_class: MyProfileClassName

Upvotes: 1

Related Questions