php Symfony 新捆绑包无法找到模板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15771229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:56:20  来源:igfitidea点击:

Symfony new bundle unable to find template

phpsymfony

提问by Joel Harkes

I made a new bundle routing.yml:

我做了一个新的bundle routing.yml:

_jihtest:
    pattern: /test
    defaults: { _controller: JihTest:Index:index }

create file directory /src/Jih/Test/... (eg. /src/Jih/Test/Recources/views/Index/index.html.twig)

创建文件目录/src/Jih/Test/...(例如/src/Jih/Test/Recources/views/Index/index.html.twig)

i might an Indexcontroller:

我可能是一个索引控制器:

class IndexController extends Controller{

    public function indexAction() {

        return $this->render('JihTest:Index:index.html.twig');

    }

}

but when go to the link it says: Unable to find template "JihTest:Index:index.html.twig".

但是当转到链接时,它说: Unable to find template "JihTest:Index:index.html.twig".

what did i do wrong/forgot?

我做错了什么/忘记了什么?

回答by Vadim Ashikhman

Controller's name matches the name of a folder. In your case the folder name starts with lowercase character "i". Rename it to "Index".

控制器的名称与文件夹的名称相匹配。在您的情况下,文件夹名称以小写字符“i”开头。将其重命名为“索引”。

回答by Erioch

The bundle name must end with Bundle, in your case:

捆绑包名称必须以 结尾Bundle,在您的情况下:

_jihtest:
    pattern: /test
    defaults: { _controller: JihTestBundle:Index:index }

And

class IndexController extends Controller{

    public function indexAction() {

        return $this->render('JihTestBundle:Index:index.html.twig');

    }
}