Ask your Symfony questions! Pay money and get answers fast! (more info)

Fatal error: Call to a member function setLabel() on a non-object Symfony

  • SOLVED

This is a sfDoctrineGuardPlugin problem.

I try to create a user:

guard/users/new

Oddly enough, I'm getting an error that has already been fixed. The error is:

Fatal error: Call to a member function setLabel() on a non-object in /home/lkrubner/dev/tastingnotes/plugins/sfDoctrineGuardPlugin/lib/form/doctrine/base/BasesfGuardUserAdminForm.class.php on line 28

[[LINK href="http://trac.symfony-project.org/ticket/7749"]]This bug was reported over a year ago, and it was fixed 6 months ago.[[/LINK]]

Just to be safe, I just deleted sfDoctrineGuardPlugin from my project and re-installed the newest version.

I'm using Symfony 1.4, running in a sort of sandbox setup.

If I go here:

plugins/sfDoctrineGuardPlugin/lib/form/doctrine/base/BasesfGuardUserAdminForm.class.php

I see this code:

<?php

/**
* BasesfGuardUserAdminForm
*
* @package sfDoctrineGuardPlugin
* @subpackage form
* @author Fabien Potencier <[email protected]>
* @version SVN: $Id: BasesfGuardUserAdminForm.class.php 25546 2009-12-17 23:27:55Z Jonathan.Wage $
*/
class BasesfGuardUserAdminForm extends BasesfGuardUserForm
{
/**
* @see sfForm
*/
public function setup()
{
parent::setup();

unset(
$this['last_login'],
$this['created_at'],
$this['updated_at'],
$this['salt'],
$this['algorithm']
);

$this->widgetSchema['groups_list']->setLabel('Groups');
$this->widgetSchema['permissions_list']->setLabel('Permissions');

$this->widgetSchema['password'] = new sfWidgetFormInputPassword();
$this->validatorSchema['password']->setOption('required', false);
$this->widgetSchema['password_again'] = new sfWidgetFormInputPassword();
$this->validatorSchema['password_again'] = clone $this->validatorSchema['password'];

$this->widgetSchema->moveField('password_again', 'after', 'password');

$this->mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_again', array(), array('invalid' => 'The two passwords must be the same.')));
}
}


The line
parent::setup(); should fix everything, yes?

So why am I getting this bug?

[UPDATE]

[[LINK href="http://groups.google.com/group/symfony-users/browse_thread/thread/7edd84ac7421e1ed"]]I tried this solution[[/LINK]]

It did not work. I ran these commands:

svn delete lib/form/doctrine/sfDoctrineGuardPlugin/

svn delete lib/form/doctrine/base/*

./symfony doctrine:build --model --forms --filters

./symfony cc



The error remains:


Fatal error: Call to a member function setLabel() on a non-object in /home/lkrubner/dev/tastingnotes/plugins/sfDoctrineGuardPlugin/lib/form/doctrine/base/BasesfGuardUserAdminForm.class.php on line 28



Also, the file BaseSfGuardGroupForm.class.php is here:

lib/form/doctrine/base

Is that correct? I'm thinking that is the wrong path. I had a similar problem when I'd copied some schema info to the wrong schema file. Though I am not aware of any such mistake now.


I'm looking at this line in BaseSfGuardUserForm.class.php:

$this->widgetSchema->setNameFormat('sf_guard_user[%s]');

This does not throw an error. And yet this line:

$this->widgetSchema['groups_list']->setLabel('Groups');

in BasesfGuardUserAdminForm.class.php throws an error, and the class is defined as:

class BasesfGuardUserAdminForm extends BasesfGuardUserForm

[update]

I notice an UPPER/lower case conflict in the above file and class names. Sure enough, this folder:

lib/form/doctrine/base

has these files:

BaseSfGuardForgotPasswordForm.class.php
BaseSfGuardGroupForm.class.php
BaseSfGuardGroupPermissionForm.class.php
BaseSfGuardPermissionForm.class.php
BaseSfGuardRememberKeyForm.class.php
BaseSfGuardUserForm.class.php
BaseSfGuardUserGroupForm.class.php
BaseSfGuardUserPermissionForm.class.php

and yet, in this folder:

lib/form/doctrine/sfDoctrineGuardPlugin/base/

I have these files (where the "s" is correctly lower case):

BasesfGuardForgotPasswordForm.class.php
BasesfGuardGroupForm.class.php
BasesfGuardGroupPermissionForm.class.php
BasesfGuardPermissionForm.class.php
BasesfGuardRememberKeyForm.class.php
BasesfGuardUserForm.class.php
BasesfGuardUserGroupForm.class.php
BasesfGuardUserPermissionForm.class.php


So I delete them all incorrect files in lib/form/doctrine/base and do "symfony cc" and yet the problem is still there. Even worse, if I do this:

./symfony doctrine:build --model --forms --filters

./symfony cc


the incorrect files reappear in lib/form/doctrine/base

Does anyone know why this would happen?


[UPDATE]

Read the details in my comments below. I had stupidly copied the schema info for the sfDoctrineGuardUser plugin to my main schema.yml file. And yet, the problems persists. Yes at this point, the schema info seems to be only where it should be:


[email protected]:~/dev/tastingnotes$ grep -R "sfGuardPermission:" *
grep: apps/tastingnotes/modules/note/templates/.#_form.php: No such file or directory
data/fixtures/.svn/text-base/sfGuard.yml.svn-base:sfGuardPermission:
data/fixtures/sfGuard.yml:sfGuardPermission:
plugins/sfDoctrineGuardPlugin/data/fixtures/fixtures.yml.sample:sfGuardPermission:
plugins/sfDoctrineGuardPlugin/data/fixtures/.svn/text-base/fixtures.yml.sample.svn-base:sfGuardPermission:
plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml:sfGuardPermission:
plugins/sfDoctrineGuardPlugin/config/doctrine/.svn/text-base/schema.yml.svn-base:sfGuardPermission:





<strong>[UPDATE]</strong>

This is interesting. Now if I run this command:

./symfony doctrine:clean-model-files

See the screenshot. I am asked to delete all the files relating to the sfDoctrineGuardUser plugin. I delete them all, then I run the same command again. There are no files to delete.

So far, so good.

But now I run this command:

./symfony doctrine:build --model --forms --filters

and now I run this again:


./symfony doctrine:clean-model-files

And once again I am asked to delete the same files that I just deleted!

<strong>The doctrine:build command recreated the files that doctrine:clean-model-files think are not in use!!!!
</strong>

How can this be possible?



[UPDATE]

I'm not sure why this did not jump out at me sooner:

[email protected]:~/dev/tastingnotes$ ./symfony doctrine:clean-model-files
>> file+ /tmp/doctrine_schema_29265.yml
>> doctrine No files found for the model named "sfGuardGroupPermission"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardGroupPermission"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardUserPermission"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardUserPermission"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardUserGroup"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardUserGroup"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardRememberKey"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardRememberKey"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardForgotPassword"
>> doctrine Deleted a total of 0 file(s)
>> doctrine No files found for the model named "sfGuardForgotPassword"
>> doctrine Deleted a total of 0 file(s)
>> autoload Resetting application autoloaders
>> autoload Resetting CLI autoloader



How can doctrine:clean-model-files both know that this models exist, and yet think they are not in use? What does "not in use" mean? If doctrine:clean-model-files sees a model defined in a schema, is that not enough to assume it is in use somewhere?


[UPDATE]

Deleted the plugin and reinstalled with a fresh copy.

I ran:

./symfony doctrine:build --model --forms --filters


I noticed that once again the model, form and filter classes for sfDoctrineGuard are being created in the wrong place, and with an uppercase "S". So I deleted all of these files:

rm lib/model/doctrine/SfGuard*

rm lib/form/doctrine/SfGuard*

rm lib/filter/doctrine/SfGuard*

./symfony cc


Still the error is there.

Why would these files appear in the wrong place, and with the wrong capitalization?



[UPDATE]


I tried this fix too:

[[LINK href="http://oldforum.symfony-project.org/index.php/m/98239/"]]http://oldforum.symfony-project.org/index.php/m/98239/[[/LINK]]

find . -name *SfGuard*.php | xargs rm

No luck.

Answers (4)

2011-01-27

mongabure ibes answers:

Hi,

For me, it's either a cache problem (but i think you clear the cache before) or an error on BasesfGuardUserForm class(lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserForm.class.php). So you must check that 'groups_list' & 'permissions_list' widgets exist in this file.


Lawrence Krubner comments:

I've cleared the cache, so it is not the problem.


Lawrence Krubner comments:

Why would there be an error in BasesfGuardUserForm? I just installed the newest version of the plugin.


mongabure ibes comments:

So "group_list" & "permissions_list" are missing in your BasesfGuardUserForm form. In my file, i have this lines on widget declaration :


'groups_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')),
'permissions_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission')),


and validators


'groups_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'required' => false)),
'permissions_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission', 'required' => false)),


Try to add this lines on your file.
I have installed the newest version too. When you run symfony doctrine:build --all-classes it seems that model does not care about the relation.
So it's not a sfDoctrineGuard problem or the sfDoctrineGuard schema is wrong.
Have you 'sf_guard_user_group' & 'sf_guard_user_permission' tables on your database?

2011-01-27

Jakub Zalas answers:

After installing plugin in a fresh project there is no such issue. Therefore I think there's something wrong with your environment.

You have <em>parent::setup()</em> call in your <em>BasesfGuardUserAdminForm</em> class. That means that either there's something wrong with its parent class (<em>BasesfGuardUserForm</em>) or you're looking at the wrong file.

First case is easy to verify. Just take a look on what's in the <em>BasesfGuardUserForm</em>. <em>group_list</em> widget should be created in <em>setup()</em> method. Regenerating form classes will fix the issue.

Second case may sound funny but I faced such an issue when I started using APC. If apc.stat option is set to off APC doesn't check if file was modified and keeps an old version in the memory. You could have different file on the file system and in the memory (the later is used).

BTW: apc.stat should be off on production but on on developemt.







Lawrence Krubner comments:

Not using APC but I'll check memcache.


Lawrence Krubner comments:

Here is the entire class. What do you think could go wrong?




/**
* sfGuardUser form base class.
*
* @method sfGuardUser getObject() Returns the current form's model object
*
* @package sf_sandbox
* @subpackage form
* @author Your name here
* @version SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
*/
abstract class BasesfGuardUserForm extends BaseFormDoctrine
{
public function setup()
{
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'first_name' => new sfWidgetFormInputText(),
'last_name' => new sfWidgetFormInputText(),
'email_address' => new sfWidgetFormInputText(),
'username' => new sfWidgetFormInputText(),
'algorithm' => new sfWidgetFormInputText(),
'salt' => new sfWidgetFormInputText(),
'password' => new sfWidgetFormInputText(),
'is_active' => new sfWidgetFormInputCheckbox(),
'is_super_admin' => new sfWidgetFormInputCheckbox(),
'last_login' => new sfWidgetFormDateTime(),
'created_at' => new sfWidgetFormDateTime(),
'updated_at' => new sfWidgetFormDateTime(),
));

$this->setValidators(array(
'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
'first_name' => new sfValidatorString(array('max_length' => 255)),
'last_name' => new sfValidatorString(array('max_length' => 255)),
'email_address' => new sfValidatorString(array('max_length' => 255)),
'username' => new sfValidatorString(array('max_length' => 128)),
'algorithm' => new sfValidatorString(array('max_length' => 128, 'required' => false)),
'salt' => new sfValidatorString(array('max_length' => 128)),
'password' => new sfValidatorString(array('max_length' => 128)),
'is_active' => new sfValidatorBoolean(array('required' => false)),
'is_super_admin' => new sfValidatorBoolean(array('required' => false)),
'last_login' => new sfValidatorDateTime(),
'created_at' => new sfValidatorDateTime(),
'updated_at' => new sfValidatorDateTime(),
));

$this->widgetSchema->setNameFormat('sf_guard_user[%s]');

$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

$this->setupInheritance();

parent::setup();
}

public function getModelName()
{
return 'sfGuardUser';
}

}


Lawrence Krubner comments:

I do this:

./symfony doctrine:build --model --forms --filters

then this:

./symfony cc

But the problem remains. You can see the error in the screenshot.