1

任何人都知道为什么我在获得最新版本的锂后会收到此异常?

( ! ) Fatal error:
  Uncaught exception 'lithium\template\TemplateException' with message
  'Could not write compiled template
  C:\Users\Master\Documents\Visual Studio 2010\Projects\PSER\PSER/resources/tmp/cache/templates/template_views_pages_index.html_0_1344056913_326.php
  to cache.' in
  C:\Users\Master\Documents\Visual Studio 2010\Projects\libraries\lithium\template\view\Compiler.php
  on line 81

( ! ) lithium\template\TemplateException:
  Could not write compiled template
  C:\Users\Master\Documents\Visual Studio 2010\Projects\PSER\PSER/resources/tmp/cache/templates/template_views_pages_index.html_0_1344056913_326.php
  to cache. in
  C:\Users\Master\Documents\Visual Studio 2010\Projects\libraries\lithium\template\view\Compiler.php
  on line 81

Call Stack

Time Memory Function Location

1 0.1070 331944 {main}( ) ..\index.php:0
2 0.2013 4387040 lithium\action\Dispatcher::run( ???, ??? ) ..\index.php:41
3 0.2013 4388248 lithium\core\StaticObject::filter( ???, ???, ???, ??? ) ..\Dispatcher.php:155
4 0.2013 4389784 lithium\util\collection\Filters::run( ???, ???, ??? ) ..\StaticObject.php:126
5 0.2014 4391752 {closure}( ???, ???, ??? ) ..\Filters.php:183
6 0.2015 4391752 lithium\util\collection\Filters->next( ???, ???, ??? ) ..\cache.php:46
7 0.2015 4391784 {closure}( ???, ???, ??? ) ..\Filters.php:202
8 0.2075 4427760 lithium\util\collection\Filters->next( ???, ???, ??? ) ..\action.php:51
9 0.2075 4427792 lithium\action{closure}( ???, ???, ??? ) ..\Filters.php:202
10 0.2198 4534776 lithium\core\StaticObject::invokeMethod( ???, ??? ) ..\Dispatcher.php:154
11 0.2198 4534808 lithium\action\Dispatcher::_call( ???, ???, ??? ) ..\StaticObject.php:75
12 0.2198 4535896 lithium\core\StaticObject::_filter( ???, ???, ???, ??? ) ..\Dispatcher.php:265
13 0.2198 4536152 lithium\action{closure}( ???, ???, ??? ) ..\StaticObject.php:119
14 0.2198 4536152 lithium\action\Controller->_invoke( ???, ???, ??? ) ..\Dispatcher.php:262
15 0.2199 4537752 lithium\core\Object->_filter( ???, ???, ???, ??? ) ..\Controller.php:198
16 0.2199 4538032 lithium\action{closure}( ???, ???, ??? ) ..\Object.php:238
17 0.2199 4538280 lithium\core\Object->invokeMethod( ???, ??? ) ..\Controller.php:184
18 0.2200 4538312 app\controllers\PagesController->view( ) ..\Object.php:165
19 0.2200 4538824 lithium\action\Controller->render( ??? ) ..\PagesController.php:32
20 0.2204 4541320 lithium\net\http\Media::render( ???, ???, ??? ) ..\Controller.php:266
21 0.2205 4550368 lithium\core\StaticObject::_filter( ???, ???, ???, ??? ) ..\Media.php:593
22 0.2206 4550616 lithium\net\http{closure}( ???, ???, ??? ) ..\StaticObject.php:119
23 0.2208 4553656 lithium\core\StaticObject::invokeMethod( ???, ??? ) ..\Media.php:590
24 0.2208 4553984 lithium\net\http\Media::_handle( ???, ???, ??? ) ..\StaticObject.php:75
25 0.2208 4555936 lithium\core\StaticObject::_filter( ???, ???, ???, ??? ) ..\Media.php:750
26 0.2209 4556184 lithium\net\http{closure}( ???, ???, ??? ) ..\StaticObject.php:119
27 0.2257 4579800 lithium\template\View->render( ???, ???, ??? ) ..\Media.php:746
28 0.2259 4583520 lithium\template\View->_step( ???, ???, ???, ??? ) ..\View.php:328
29 0.2259 4587040 lithium\core\Object->_filter( ???, ???, ???, ??? ) ..\View.php:389
30 0.2260 4587304 lithium\template{closure}( ???, ???, ??? ) ..\Object.php:238
31 0.2260 4587336 lithium\template\view\adapter\File->template( ???, ??? ) ..\View.php:386
32 0.2272 4588624 lithium\template\view\Compiler::template( ???, ??? ) ..\File.php:133

我很确定路径中的斜线(向前或向后)不是问题。我创建了一个快速的小测试脚本,证明正斜杠和反斜杠可以在 Windows 的路径中共存。结果路径是:

C:/Users/Master/Documents/Visual Studio 2010/Projects/PHP Prototyping/PHP Prototyping\ABC\testFile.txt

代码示例如下:

<?php
    $myFile = $_SERVER['DOCUMENT_ROOT'] . '\\ABC\\testFile.txt';
    $fh = fopen($myFile, 'w') or die('can\'t open file');
    $stringData = 'Bobby Bopper\n';
    fwrite($fh, $stringData);
    $stringData = 'Tracy Tanner\n';
    fwrite($fh, $stringData);
    fclose($fh);
?>
4

2 回答 2

3

您的resources目录不可写,因此 Lithium 无法将编译后的模板写入resources/tmp/cache/templates.

编辑:还要仔细检查resources目录是否存在,因为它不应该在 git repo 中进行版本控制。

您可以使用此代码段动态创建它,并具有正确的权限:https ://gist.github.com/1009460 ( config/bootstrap/libraries.php)

于 2012-08-04T17:38:59.047 回答
0

问题是缓存下的模板文件夹不存在。

该目录不存在,因为我没有将它添加到源代码管理中,因为 tmp 下的东西无论如何都不应该从 dev 转到 prd。写入模板缓存的问题一直存在,但最近对框架的更改导致 php 抛出错误而不是黑洞错误。

我在 template/view/Compiler.php 中添加了一些代码来处理丢失目录的创建。代码块的第一行是 68,没有改变。同样,结束行没有更改,因此您可以将添加的内容与之前的内容进行比较。

    $compiled = static::compile(file_get_contents($file));

    $pathIsWritable = is_writable($cachePath);      
    if(!$pathIsWritable){
        $exMessage = ' File not writable. ';
        if(!file_exists($cachePath)) {
            $exMessage .= 'Path to file invalid. ';
            $dirCreated = mkdir($cachePath, 0777, true);

            if($dirCreated) {
                $pathIsWritable = true;
            }
            else {
                $exMessage .= 'Attempt to create the directory path failed.';   
            }
        }           
    }

    if ($pathIsWritable && file_put_contents($template, $compiled) !== false) {
        foreach (glob("{$options['path']}/template_{$oname}_*.php") as $expired) {
于 2012-08-06T00:20:19.467 回答