Override executeIndex in admin modules
-
29-09-2019 - |
Pergunta
In the administration generated by symfony, how do I override the method executeIndex() ?
I want to list only the items that have a specific state, and all I found in cache/backend/dev/modules/auto.../ was :
$this->pager = $this->getPager();
How do I change the query used by the pager ?
Solução
There's no need to ovveride action or templates just to filter your results. It's better to use table_method option in generator.yml See http://www.symfony-project.org/jobeet/1_4/Doctrine/en/12#chapter_12_sub_table_method
Outras dicas
The same way as you would override any other methods in existing classes eg configure()
in a form. Open up apps/yourapp/yourmodule/actions/actions.class.php
and add:
public function executeIndex(sfWebRequest $request)
{
// do whatever you want to here.
}
You might find it a good idea to look in your cache for the auto generated version, and copy the required parts from that into your overridden method, before you start adjusting - this gives you a working base to start from.
Similar to what manu says. But I would suggest you over ride getPager rather than executeIndex. Bit nicer ... but does essentially the same as manu's answer.
public function getPager()
{
$pager = parent::getPager();
$pager->setQuery(Doctrine_Core::getTable('Content')->getListeByState('Published'));
return $pager;
}
public function executeIndex(sfWebRequest $request)
{
parent::executeIndex($request);
$this->pager->setQuery(Doctrine_Core::getTable('Content')->getListeByState('Published'));
}