开发者

sfDoctrineGuardPlugin and admin filters

开发者 https://www.devze.com 2023-04-08 04:24 出处:网络
I have an admin that uses sfDoctrineGuardPlugin. I also have another table, sf_guard_user_profile, that extends the sf_guard_user table, to include more fields, such as address, age etc

I have an admin that uses sfDoctrineGuardPlugin. I also have another table, sf_guard_user_profile, that extends the sf_guard_user table, to include more fields, such as address, age etc

My problem is, I am embedding the profile (sf_guard_user_profile) information into the sf_guard_user record when viewing the records in the admin generated module. This works fine, but I'd like to then be able to use some of the filters from the sf_guard_user_profile table.

I have tried to add these into the generator.yml file, but I this throws an error

generator.yml

.......开发者_如何学编程............

  filter:
    display: [username, email_address, address_1, is_active ]

Widget "address_1" does not exist.

address_1 is a field in sf_guard_user_profile

Is this possible to do?

Thanks


Ok, so I had to do a little bit of work in the sfGuardUserFormFilter class,

  $this->widgetSchema['age'] =  new sfWidgetFormInputText(array(
      'label' => 'Age'
  ));

  //Type of validator for filter
  $this->validatorSchema['age'] = new sfValidatorPass(array ('required' => false));

public function getFields()
{
  $fields = parent::getFields();
  $fields['age'] = 'age';
  return $fields;
}


public function addAgeColumnQuery($query, $field, $value)
{
     $rootAlias = $query->getRootAlias();

     $query->where('p.age LIKE ?', '%'.$value.'%');

     //remember to return the $query!
     return $query;
}

I could then use the age field in the generator.yml file.

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号