自定义/添加页面到管理生成器的最佳方法是什么?

发布于 2024-08-26 10:43:02 字数 352 浏览 3 评论 0原文

我正在使用 Symfony 1.4 和 Doctrine。

我的应用程序的后端是使用 Symfony 的管理生成器构建的。 当我想展示基本的东西时它非常有用。

但关于如何增强它和添加新页面的文档并不多。

让我们举个例子: 我想在一页上列出已发布的项目,在另一页上列出即将发布的项目。我在我的应用程序中使用了多种方法,但无法找出最好的方法是什么:

  • 使用过滤器,然后根据您所在的位置修改模板?
  • 创建另一个模块调用不同的table_method
  • 还有其他我不知道的技术吗?

这里的最佳实践是什么? 你们通常如何定制您的管理员?

I'm using Symfony 1.4 and Doctrine.

My application's backend was built using Symfony's admin generator.
It works great when I want to display basic stuff.

But tehre's not a lot of documentation on how to enhance it and add new pages.

Let's take an example:
I want to list published items on one page and to-be-published items on another one. I've used several ways to that in my application but can't figure out what the best way is:

  • playing with filters and then modify templates depending on where you are?
  • creating another module calling a different table_method?
  • some other technique I don't know about?

What's the best practice here?
How do you guys usually do to customize your admin?

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

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

发布评论

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

评论(1

潜移默化 2024-09-02 10:43:03

在这里无耻地自我推销。我写了一篇博客文章 本周关于自定义管理生成器 - 我所做的一件事是将新页面等添加到生成器中。我的做法可能有点硬核,但效果很好:-)

开始寻找的最佳位置是为您的模块自动生成的操作类,并在您的 app/module/actions/actions.txt 中扩展它。 class.php 文件。特别是设置 ORM 分页器的索引操作。您应该能够使用 ORM 中的任何查询来为 ORM 寻呼机提供数据 - 在我需要更改它的情况下,我使用以与正常方式相同的方式生成的 Doctrine 查询来传递给寻呼机。这意味着我可以自定义显示哪些字段,包括在单个查询中加入的其他表中的字段等。这就是上面提到的“表格方法”。

过滤器也同样有效 - 这取决于您的用例以及过滤器是否适合,特别是对于显示。如果您想要一个 /showpublisheditems 页面,那么我会使用新的操作和寻呼机的新查询。如果您想要即时定制,请使用过滤器选项。

我认为过滤器文档也有一些地方缺乏 - 快速提示,他们在顶级过滤器类(lib/filter/...)中寻找一个 addYourColumnNameColumnQuery() 方法,该方法需要一个传入的查询并使用例如 addWhere("x.column_name = ?", $foo) 到传入的查询。

布莱赫:-) 抱歉,这有点令人费解,但希望它能有帮助! :-)

Shameless self-promotion here. I wrote up a blog post this week on customising the admin generator - one of the things I did was to add new pages etc into the generator. The way I did it is probably a bit hardcore, but it works nicely :-)

The best place to start looking is the auto-generated actions class for your module and extending it in your app/module/actions/actions.class.php file. In particular, the index action which sets up the ORM pager. You should be able to use any query from your ORM to supply your ORM pager with data - in cases where I've needed to alter it, I use a Doctrine query generated in the same way as normal to pass to the pager. This means that I can customise what fields are displayed, including ones from other tables joined in etc in a single query. This is your 'table method' mentioned above.

Filters will work just as well - it depends on your use case and whether filters are appropriate, particularly for display. If you want a /showpublisheditems page, then I'd go with a new action and the new query for the pager. If you want on-the-fly customisation, then go with the filter option.

The filter docs I thought were a bit lacking in places too - quick tip, they look for a addYourColumnNameColumnQuery() method in your top-level filter class (lib/filter/...) which takes a query passed in and uses eg addWhere("x.column_name = ?", $foo) to the query passed in.

Bleh :-) sorry, that was a bit of a brain dump, but hopefully it helps! :-)

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