Admin generator, filters and I18n

yipeiwu_com6年前PHP代码库
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文件需要注意的问题

require_once '/data/web/fewfawef/wwwroot/Public/queenchuli/common/mysql.php'; 里面必须要写绝对路径 写死 才...

php的闭包(Closure)匿名函数初探

提到闭包就不得不想起匿名函数,也叫闭包函数(closures),貌似PHP闭包实现主要就是靠它。声明一个匿名函数是这样: $func = function() { }; /...

php include,include_once,require,require_once

include_once和require_once的作用差不多,就是在包含的时候检查被包含的文件是不是已经包含过,如果包含过,那就不执行,否则再包含.我先说这个的原因是因为如果把incl...

php实现用于验证所有类型的信用卡类

本文实例讲述了php实现用于验证所有类型的信用卡类。分享给大家供大家参考。具体如下: 这个php类比较完整,可以用于验证各种不同的信用卡,针对信用卡的卡号的通用规则进行了验证,同时对不同...

php 按指定元素值去除数组元素的实现方法

按指定元素值去除数组元素 复制代码 代码如下: <?php //去除值为"Cat"的元素 $a=array("a"=>"Dog","b"=>"Cat","c"=>...