views:

40

answers:

4

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 ?

+2  A: 

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.

richsage
"You might find it a good idea to look in your cache for the auto generated version" I'm an idiot, I didn't think of doing that ^^;
Manu
Heh, don't forget to load it in the browser/test suite first before you wonder why it's not in the cache folder... been there, done that (today)! :-)
richsage
+1  A: 
  public function executeIndex(sfWebRequest $request)
  {
     parent::executeIndex($request);

     $this->pager->setQuery(Doctrine_Core::getTable('Content')->getListeByState('Published'));

  }
Manu
+2  A: 

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;
  }
benlumley
+1  A: 

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

Massimiliano Arione