I have a table/class called ImportBundle
. ImportBundle
has an active
flag that can be set to 1 or 0.
On one of my admin pages I have a select field showing all the ImportBundle
s in my database. I开发者_运维百科 would like to only see the active ones.
How do I change this?
Do you want to change the default active value, remove the active field, or alter the base query?
Set the default
Add a getFilterDefaults
method to ImportBundleGeneratorConfiguration
:
public function getFilterDefaults()
{
return array('active' => true);
}
Remove the field
Either unset the field from the filter in ImportBundleFormFilter
or change the display
option under the filter
generator.yml heading. If ImportBundleFormFilter
is used elsewhere, you may need to extend it to unset the field.
Alter the query
Set the table_method
option in generator.yml or on the filter itself. See more instructions here.
If your select field is a sfWidgetFormDoctrineChoice, then you should set the table_method option.
For example, if your have Model with many-to-many relation to Related:
class ModelFormFilter extends BaseModelFormFilter
{
public function configure()
{
$this->getWidget('related_list')->setOption('table_method', 'getActive');
}
}
class RelatedTable extends Doctrine_Table
{
public function getActive()
{
return $this->createQuery('r')
->where('r.is_active = ?', true)
->execute();
}
}
精彩评论