不使用模板 Symfony 2 [英] Not using templates Symfony 2

查看:27
本文介绍了不使用模板 Symfony 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难找到有关该主题的任何内容.如果我想使用控制器来简单地呈现一个静态页面,例如 about.php,该怎么办?当我尝试以下操作时,我收到一个找不到模板的错误.

公共函数aboutAction(){return $this->render('FooBundle:Default:about.php');}

解决方案

无需创建控制器即可渲染页面:

foo_about:路径:/关于默认值:_controller: FrameworkBundle:Template:template模板:'FooBundle:默认:about.html.php'

about.html.php 必须位于 FooBundleResources/views/Default/ 目录下.

参见如何在没有自定义控制器的情况下渲染模板>

I am having a hard time finding anything on the topic. What if I wanted to use a controller to simply render a static page such as about.php? When I try the following I get a template not found error.

public function aboutAction()
{
    return $this->render('FooBundle:Default:about.php');
}

解决方案

You can render the page without creating a controller:

foo_about:
    path: /about
    defaults:
        _controller: FrameworkBundle:Template:template
        template: 'FooBundle:Default:about.html.php'

The about.html.php must be located under Resources/views/Default/ directory of the FooBundle.

See How to render a Template without a custom Controller

这篇关于不使用模板 Symfony 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆