Symfony2,包含文件错误

时间:2012-10-25 10:40:07

标签: php symfony

我遇到了一个奇怪的问题。我只有两个php页面:Index.html.phpHeader.php只包含在Symfony2项目上运行的HTML代码。索引页面包含一个非常正常的包含:include "Header.php"。问题是,当我第一次加载索引页面正常呈现时,一切都已就绪,但第二次刷新页面时,我收到了这个错误:

at ErrorHandler ->handle ('2', 'include(Header.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory', '', '30', array('template' => object(FileStorage), 'parameters' => array('app' => object(GlobalVariables)), '__template__' => object(FileStorage), 'this' => object(PhpEngine), 'app' => object(GlobalVariables), 'view' => object(PhpEngine)))
in wamp\www\**\src\**\**Bundle/Resources/views/Default/Index.html.php at line 30 

at include ()
in wamp\www\**\src\**\**Bundle/Resources/views/Default/Index.html.php at line 30 
at require ('')
in C:\wamp\www\**\app\cache\dev\classes.php at line 2490 

at PhpEngine ->evaluate (object(FileStorage), array('app' => object(GlobalVariables)))
in C:\wamp\www\**\app\cache\dev\classes.php at line 2440  

at PhpEngine ->render ('**Bundle:Default:Index.html.php', array())
in C:\wamp\www\**\app\cache\dev\classes.php at line 2778 

at PhpEngine ->renderResponse ('**Bundle:Default:Index.html.php', array(), null)
in C:\wamp\www\**\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine.php at line 87

at DelegatingEngine ->renderResponse ('**Bundle:Default:Index.html.php', array(), null)
in C:\wamp\www\**\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php at line 99 

at Controller ->render ('**Bundle:Default:Index.html.php')
in C:\wamp\www\**\src\**\**Bundle\Controller\DefaultController.php at line 15

at DefaultController ->indexAction ()

at call_user_func_array (array(object(DefaultController), 'indexAction'), array())
in C:\wamp\www\**\app\bootstrap.php.cache at line 1421

at HttpKernel ->handleRaw (object(Request), '1')
in C:\wamp\www\**\app\bootstrap.php.cache at line 1385 

at HttpKernel ->handle (object(Request), '1', true)
in C:\wamp\www\**\app\bootstrap.php.cache at line 1561

at HttpKernel ->handle (object(Request), '1', true)
in C:\wamp\www\**\app\bootstrap.php.cache at line 612

at Kernel ->handle (object(Request))
in C:/wamp/www/**/web/app_dev.php at line 28

我检查了文件,它确实存在于与索引文件相同的目录中。我检查了信件的情况。请注意,该项目是由Symfony制作的,并且一切顺利,但是当我创建一个Sf2.1项目并将文件放在上面时,我遇到了这个问题。我正在使用Windows7和WampServer 2.1。我希望我已经提供了足够的关于这个问题的信息。

1 个答案:

答案 0 :(得分:0)

在第一次请求时,php呈现新模板,在下一次请求时,php从缓存中呈现模板。因为Header.php没有缓存php抛出文件未找到异常。

使用渲染功能而不是包含。检查此Including other Templates,或者您可以将完整路径传递给include()