自动为 Zend Framework 等控制器操作渲染 Symfony2 模板

发布于 2025-01-01 04:32:45 字数 348 浏览 3 评论 0原文

我来自 Zend Framework 背景,创建页面的过程是:

  1. 创建一个控制器
  2. 创建一个空操作
  3. 为控制器创建一个文件夹 创建
  4. 一个与控制器操作名称匹配的文件并将其放在控制器的目录中

当您通过 http://host/controller/action 访问应用程序时,视图文件会自动呈现。

我是否可以在 Symfony2 中执行此操作,这样我就不必为每个控制器/操作创建路由条目?并自动渲染每个动作的树枝模板?

提前致谢

I am coming from a Zend Framework background, and the process for creating a page is:

  1. Create a controller
  2. Create an empty action
  3. Create a folder for the controller
  4. Create a file matching the name of the controller action and place it in the directory for the controller

When you access the application via http://host/controller/action the view file is automatically rendered.

Is it possible for me to do this within Symfony2 so that I do not have to create routing entries for each controller/action? and automatically render the twig templates for each action?

Thanks in advance

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

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

发布评论

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

评论(1

旧夏天 2025-01-08 04:32:45

您可以使用 SensioFrameworkExtraBundle

 class MyController extends Controller {
     /**
      * @Template()
      */
    public function myAction() { 
        return array(); 
    }
 }

模板是Resources/views/My/my.twig.html。请注意,您必须在操作方法中返回一些内容。

You can use the @Template annotation from the SensioFrameworkExtraBundle.

 class MyController extends Controller {
     /**
      * @Template()
      */
    public function myAction() { 
        return array(); 
    }
 }

The template is Resources/views/My/my.twig.html. Note that you have to return something in the action method.

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