简体   繁体   English

Symfony2 Twig_Error_Loader-Twig找不到模板

[英]Symfony2 Twig_Error_Loader - Twig doesn't find templates

I look for a while, but don't find a solution. 我寻找了一段时间,但找不到解决方案。 I have a Symfony2 project that I'm trying to deploy. 我有一个要部署的Symfony2项目。 The strcture that I have is this: 我的结构是这样的:

/www/my_app/ -> where lives all symfony folders (app, bin, src and vendor) but 'web'
/www/public_html/my_app/ -> this is the 'web' folder renamed to 'my_app'

With this structure I change the routes in app.php: 通过这种结构,我更改了app.php中的路由:

$loader = require_once __DIR__.'/../../my_app/app/bootstrap.php.cache';
require_once __DIR__.'/../../my_app/app/AppKernel.php';

And I get this error: 我得到这个错误:

Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'The "D:\www\public_html\my_app\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle/Resources/views" directory does not exist.' in D:\www\my_app\vendor\twig\twig\lib\Twig\Loader\Filesystem.php on line 93
Twig_Error_Loader: The "D:\www\public_html\my_app\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle/Resources/views" directory does not exist. in D:\www\my_app\vendor\twig\twig\lib\Twig\Loader\Filesystem.php on line 93

The problems is that that files that Twig are trying to load no lives in "D:\\www\\public_html\\my_app\\vendor", but in "D:\\www\\my_app\\vendor". 问题在于,Twig尝试加载的文件没有生存在“ D:\\ www \\ public_html \\ my_app \\ vendor”中,而是生存在“ D:\\ www \\ my_app \\ vendor”中。

I hope that you can get the problem. 希望您能解决这个问题。 I'm running the app within apache. 我正在apache中运行该应用程序。

Thanks in advance for any comment. 预先感谢您的任何评论。

I'm not sure if it would help in your case, but when I want to load twig templates from other directories in controller I run: 我不确定这是否对您有帮助,但是当我想从控制器中其他目录加载树枝模板时,我运行:

$this->get('twig.loader')->addPath('../app');       

This is just example how I tell Twig - "I want also use templates from other ../app path". 这只是我告诉Twig的示例-“我也要使用其他../app路径中的模板”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM