在Symfony生成的管理中,如何覆盖方法ExecuteIndex()?

我想仅列出具有特定状态的项目,以及我在CACHE/BACKEND/DEV/模块/Auto .../WAS中找到的所有内容:

$this->pager = $this->getPager();

如何更改Pager使用的查询?

有帮助吗?

解决方案

无需仅仅是为了过滤结果而进行排卵或模板。最好在发电机中使用table_method选项。 http://www.symfony-project.org/jobeet/1_4/doctrine/en/12#chapter_12_sub_table_method

其他提示

就像您覆盖现有类中的任何其他方法一样,例如 configure() 以一种形式。打开 apps/yourapp/yourmodule/actions/actions.class.php 并添加:

public function executeIndex(sfWebRequest $request)
{
  // do whatever you want to here.
}

您可能会发现,在开始调整之前,在缓存中查看自动生成的版本,并将所需部分从该版本中复制到覆盖方法中是一个好主意 - 这为您提供了一个工作基础。

与Manu所说的类似。但是我建议您过度骑行getPager,而不是executeIndex。更好...但是与Manu的回答基本相同。

  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'));

  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top