2012-12-23 74 views
0

试图正确使用Smarty,我创建了一个配置文件。文件结构是这样的:Smarty:找不到配置文件

/Smarty/ 
/Smarty/cache 
/Smarty/configs 
/Smarty/configs/main.conf 
/Smarty/plugins 
/Smarty/sysplugins 
/Smarty/templates_c 
/templates/ 
/templates/main.tpl 
index.php 

在main.tpl我尝试加载从/Smarty/configs/main.conf的main.conf:http://www.smarty.net/docs/en/language.config.variables.tpl 这不起作用: {config_load "main.conf"}这里解释(“致命错误:未捕获的异常‘SmartyException’有消息‘无法读取配置文件‘在... main.conf’’”),然而,这没有问题:

{config_load "/var/www/vhosts/*domain*/subdomains/cms/httpdocs/Smarty/configs/main.conf"} 

为什么没有第一个例子工作?我之前设置了配置目录:

$smarty->setConfigDir(SMARTY_DIR.'configs/'); 

但找不到配置目录。有人可以帮我吗?提前致谢!

+0

在调用'setConfigDir'来查看实际存在的路径后,打印'$ smarty-> getConfigDir()'。 – Eugene

+0

@Eugene该路径似乎是正确的。它print_rs:“Array([0] =>/var/www/vhosts/* domain */subdomains/cms/httpdocs/Smarty/configs /)” –

+0

你可以检查文件的权限吗?也许该文件没有读取权限。 –

回答

1

我得到同样的问题,我有smarty集成在CodeIgniter中。这是我做过什么
1)$this->smarty->addConfigDir('YourPath');
你的情况可能会变得$smarty->addConfigDir('YourPath');

然后在浏览器打印var_dump($this->smarty->getConfigDir());
你的情况可能会变得var_dump($smarty->getConfigDir());

2)之后,你可能会改变$this->smarty->setConfigDir('YourPath'); 你的情况可能会变得$smarty->setConfigDir('YourPath');
它的作品在我的情况。

0

这里是我使用配置的样本,它的正常工作与我

/////Smarty including 
require_once('libs/Smarty.class.php'); 
$smarty = new Smarty(); 
$smarty->template_dir = 'template'; // template folder 
$smarty->compile_dir = 'cache'; // Create a Folder Cache with 777 Permission 

此设置正常工作与最新版本的Smarty Smarty的3.x的