覆盖管理模块中的executeIndex

发布于 2024-09-27 02:45:31 字数 205 浏览 0 评论 0原文

在 symfony 生成的管理中,如何重写方法executeIndex()?

我只想列出具有特定状态的项目,而我在cache/backend/dev/modules/auto.../ 中找到的所有内容是:

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

如何更改寻呼机使用的查询?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

对风讲故事 2024-10-04 02:45:31

与重写现有类中的任何其他方法相同,例如表单中的 configure() 。打开 apps/yourapp/yourmodule/actions/actions.class.php 并添加:

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

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

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.

霊感 2024-10-04 02:45:31

与马努所说的类似。但我建议你不要使用 getPager 而不是executeIndex。好一点......但本质上与马努的答案相同。

  public function getPager()
  {
     $pager = parent::getPager();
     $pager->setQuery(Doctrine_Core::getTable('Content')->getListeByState('Published'));
     return $pager;
  }

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;
  }
半衾梦 2024-10-04 02:45:31

无需仅仅为了过滤结果而覆盖操作或模板。
最好在generator.yml中使用table_method选项
请参阅http://www.symfony-project.org/jobeet/ 1_4/Doctrine/en/12#chapter_12_sub_table_method

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

烟雨凡馨 2024-10-04 02:45:31
  public function executeIndex(sfWebRequest $request)
  {
     parent::executeIndex($request);

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

  }
  public function executeIndex(sfWebRequest $request)
  {
     parent::executeIndex($request);

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

  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文