多个action.class.php

发布于 2024-11-26 16:52:18 字数 337 浏览 2 评论 0原文

我确实有一个模块,例如帐户。当然,您会在 acount/actions/action.class.php 中找到一个名为的文件。

PHP 文件action.class.php 变得越来越大。可以延长吗?

举个例子:

/account/action/action.class.php
/account/action/action2.class.php

如果可能的话,action.class.php和action2.class.php中的代码是什么样的?和/或我应该在配置 ymal 文件中的哪里输入内容?

提前致谢!

克拉猎手

I do have an module e.g. account. Of course you will find a file called in acount/actions/action.class.php.

The PHP-file action.class.php is getting big. Is it possible to extend it?

for an example:

/account/action/action.class.php
/account/action/action2.class.php

If it is possible, how does the code look like in action.class.php and in action2.class.php? And/or where should I enter something in a config-ymal-file?

Thanks in advance!

Craphunter

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

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

发布评论

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

评论(4

从此见与不见 2024-12-03 16:52:18

Symfony 操作可以以两种方式声明:

  1. 继承自 sfActions 的大 actios.class.php 文件
  2. 继承自 sfActions 的多个 xxxAction.class.php 文件

两者基本相同,但不能混合使用(您必须决定是否想要123123 个文件,每个操作 1 个,或一个大文件)。

这是有关此问题的 symfony 参考: Symfony 前端控制器 - 操作 检查操作部分。

Symfony actions can be declare in two flavors:

  1. A big actios.class.php file that inherit from sfActions
  2. Multiple xxxAction.class.php file that inherit from sfAction

The are both basically the same but these cant be mixed (you must decide if you want 123123 files, 1 per action, or one big fat file).

Here its the symfony reference on this matters: Symfony Front Controller - Actions check the Action section.

瞳孔里扚悲伤 2024-12-03 16:52:18

听起来动作类变得太大了,因为里面的东西太多了。我建议将其分解为多个模块或将逻辑代码的相关部分移动到您的模型中。

为 action2 文件添加 include 并不是 Symfony 1.4 的预期用途,而且很可能会导致各种其他令人头疼的问题。

It sounds like the action class is getting too big because you have too much stuff in it. I would suggest breaking it into multiple modules or moving relevant parts of the logic code into your models.

Adding an include for an action2 file is not how Symfony 1.4 is intended to be used and will likely just lead to all kinds of other headache.

拒绝两难 2024-12-03 16:52:18

PHP 不支持像 C# 那样的“部分类”。因此,您有两个选择:

  • 通过创建继承自 sfActionbaseActions 类来创建继承链。然后创建继承自 baseActionsMainActions 类。您可以添加不同的继承层。

  • 将函数分组到不同的类中。覆盖操作文件中的 execute() 函数,并手动调用所需类上的函数。

PHP doesn't support 'partial classes' like C#. So you have two options:

  • Create an inheritance chain, by creating a baseActions class which inherits from sfAction. Then create your MainActions class which inherits from baseActions. You can add different layers of inheritance.

  • Group functions in seperate classes. Override the execute() function in your actions file, and manually call the function on the class you need.

万水千山粽是情ミ 2024-12-03 16:52:18

还要考虑您在操作(控制器)中实现的某些行为是否属于模型(或视图)。如果确实属于该操作,只需遵循 guiman 的建议并为每个继承 sfAction 的类创建一个操作。

如果我有一个基于模型(由 CLI 生成)的 CRUD 模块,并且我必须为该模型定义其他行为,我倾向于创建另一个模块来包含这些行为。例如,考虑一个模型文章。我可以为 CRUD 行为(生成)创建一个 article module,为审核、激活等其他行为创建 article_support,也许还有 article_ajax 用于异步请求。

Also consider if some of the behavior you're implementing in the action (controller) belongs to the model (or the view) instead. If the really belongs to the action just follow guiman's advice and create an action per class inheriting sfAction.

If I have a CRUD module based on a model (as generated by the CLI), and I have to define additional behaviors for that model, I tend to create another module to contain that behaviours. E.g., considering a model Article. I could create an article module for the CRUD behaviors (generated), article_support for additional behaviors like moderation, activation, etc. and perhaps article_ajax for async requests.

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