无法加载模板文件

时间:2014-03-10 07:24:52

标签: templates zend-framework smarty

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file '../index/index.tpl'' in 
/var/www/docs/sw.com/public/library/Smarty/sysplugins/smarty_internal_template.php:174 
Stack trace: 
#0 /var/www/docs/sw.com/public/library/Smarty/sysplugins/smarty_internal_template.php(551): Smarty_Internal_Template->isExisting(true) 
#1 /var/www/docs/sw.com/public/application/tmp/smarty_compile/898ca70906754084b81f61d3ce7baee3b11bd8d3.file.layout.tpl.php(46): Smarty_Internal_Template->getRenderedTemplate() 
#2 /var/www/docs/sw.com/public/library/Smarty/sysplugins/smarty_internal_template.php(436): include('/var/www/docs/s...') 
#3 /var/www/docs/sw.com/public/library/Smarty/sysplugins/smarty_internal_template.php(568): Smarty_Internal_Template->renderTemplate() 
#4 /var/www/docs/sw.com/public/library/Smarty/Smarty.class.php(328): Smarty_Internal_Template->getRenderedTemplate() 
#5 /var/www/docs/sw.com/public/library/Smarty/Smarty.class.php(370): Smarty->fetch('/var/www/docs/s...', NULL, NULL, NULL, true) 
#6 /v in /var/www/docs/sw.com/public/library/Smarty/sysplugins/smarty_internal_template.php on line 174 

我正在使用带有zend框架的smarty模板,并且我创建了一个像admin这样的模块。在那个模块控制器工作,layout.tpl文件也工作但是问题是当我在layout.tpl中添加包含文件语法时文件那个时间相同的错误即将来临。

IndexController.php

<?php

class Admin_IndexController extends Models_UserCommonController 
{

function init() 
    {

    parent::init();

}

public function indexAction()
 {
    $this->view->assign('T_Body', '../index/index.tpl');
}
}
?>

layout.tpl    
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>{$SITE_TITLE}</title>
</head>

<body>

<p>Hello</p>

{include file="$T_Body"}

</body>
</html>

index.php

管理

我在Windows中做了同样的事情,但是在ubuntu中它不起作用。 我设置了所有权限并检查了所有路径。 默认模块在ubuntu中工作但管理模块不工作

1 个答案:

答案 0 :(得分:1)

不太确定Smarty的实现,但你必须记住PHP的工作目录是你的项目根路径。

您可能希望以这种方式绝对分配它:

$this->view->assign('T_Body', __DIR__ . '/../index/index.tpl');

请记住,这只适用于Zend Framework 2!您的代码表明您没有使用第二个版本,而是使用ZF1。否则,您绝对应该继续前进并使用名称空间,并按照教程了解如何构建控制器。