网站地图    收藏   

主页 > 后端 > php进阶知识 >

You need to modify your EntityFormFilter (where Entity is yo

来源:自学PHP网    时间:2014-09-18 13:09 作者: 阅读:

[导读] You need to modify your EntityFormFilter (where Entity is your object class - Article, Book, etc.)....

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/

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论