>  기사  >  php教程  >  Admin generator, filters and I18n

Admin generator, filters and I18n

WBOY
WBOY원래의
2016-06-13 12:05:05788검색

Three easy steps

1) configure function
Add an input for each field you want to include in your filter

复制代码 代码如下:


$this->widgetSchema['name'] = new sfWidgetFormFilterInput(array('with_empty' => false));
$this->validatorSchema['name'] = new sfValidatorPass(array('required' => false));


2) add a query modification when filtering for that field
I've done it for Doctrine. Pay atention to the method name addFIELDColumnQuery.

复制代码 代码如下:


public function addNameColumnQuery(Doctrine_Query $query, $field, $values)
{
if (is_array($values) && isset($values['text']) && '' != $values['text'])
{
$query->leftJoin('r.Translation t')
// ->andWhere('t.lang = ?', $especify_one_language) // or it will search in all of them
->andWhere('CONCAT(t.name, t.shortname) like ?', '%' . $values['text'] . '%');
}
}


3) Add your searching fields

复制代码 代码如下:


public function getFields()
{
return parent::getFields() + array('name' => 'Text');
}


From: http://oldforum.symfony-project.org/index.php/t/24350/
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.