model-view-controller - Symfony Actions 命名空间,还是更好的方法?

标签 model-view-controller namespaces symfony1 action

在 Rails 中,您可以将 Controller 组织到文件夹中,并通过命名空间保持结构良好。我正在 Symfony 1.4 中寻找类似的组织结构。

我想在一个 Action 文件夹中组织多个 actions.class.php 文件,但我遇到的只是使用独立的 Action 文件,每个 Action 一个......像这样:

# fooAction.class.php
class fooAction extends sfActions {
  public function executeFoo() {
    echo 'foo!';
  }
}

但是我必须开发一个全新的路由系统才能将多个操作放入该文件中,这很......愚蠢。

真的,我只是想让 Symfony 变成 Rails,(再一次,愚蠢,但我在这个项目中坚持使用 Symfony)所以我想知道是否有更好的方法......?

谢谢。

最佳答案

An alternative action syntax is available to dispatch the actions in separate files, one file per action. In this case, each action class extends sfAction (instead of sfActions) and is named actionNameAction. The actual action method is simply named execute.


class indexAction extends sfAction
{
  public function execute($request)
  {
    // ...
  }
}

A Gentle Introduction to symfony - chapter 06: Inside the controller layer, subsection Alternative Action Class Syntax

关于model-view-controller - Symfony Actions 命名空间,还是更好的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4251945/

相关文章:

php - 模型在 MVC 编程中应该走多远?

php - CakePHP:使用不同的数据库关联两个模型?

scope - Tcl:如何从不同的命名空间调用 proc,同时从它的命名空间传递一个变量给我的 proc?

php - 如何在 symfony 中使用数据库

symfony1 - Symfony 无法打开我的 sfDoctrineDatabase.class.php

symfony1 - 在迁移期间添加新的枚举列

c# - 下面的PUT方法代码中是否需要int id?

python - 使用 Web2Py 创建通用 Controller 功能

php - 根据当前命名空间动态使用不同的类

clojure - Clojure 使用哪些命名空间进行定义