0

我遇到了一个奇怪的问题。我只有两个 php 页面:Index.html.php并且只包含在项目Header.php上运行的 HTML 代码。Symfony2Index 页面包含一个非常正常的 include: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。我希望我已经提供了有关该问题的足够信息。

4

1 回答 1

0

在第一个请求 php 呈现新的模板,在下一个请求 php 从缓存中呈现模板。由于 Header.php 未缓存 php 抛出未找到文件异常。

使用渲染函数而不是包含。检查此包括其他模板,或者您可以将完整路径传递给 include()

于 2012-10-25T10:55:50.340 回答