无法在smarty中加载配置文件

时间:2013-07-30 19:10:07

标签: php smarty fatal-error php-5.4

我是PHP和smarty的新手,我不知道如何解决这个问题。这是关于我的项目目录的粗略概念

MyProject的

->include
->configs->site.conf
MyProject ->include->config.php
MyProject ->libs->smarty->plugins
MyProject ->libs->smarty->sysplugins
MyProject ->libs->smarty->debug.tpl
MyProject ->libs->smarty->Smarty.class.php
MyProject ->libs->smarty->SmartyBC.class.php
MyProject ->presentation->templates->test.tpl
MyProject ->presentation->templates_c
MyProject ->presentation->application.php
MyProject ->index.php

我在site.conf文件中定义了一个变量。网站标题。我正在尝试在 test.tpl 中加载我的配置文件,就像这样......

{$smarty->configLoad('site.conf')}

我也试过了......

{config_load file='site.conf'}

但是我收到了这个错误......

Fatal error: Uncaught exception 'SmartyCompilerException' with message 
'Syntax Error in template "E:\xampp\htdocs\MyProject\presentation\templates\test.tpl"
on line 1 "{$smarty.configLoad('site.conf')}" $smarty.configLoad is invalid' 
in  E:\xampp\htdocs\MyProject\libs\smarty\sysplugins
\smarty_internal_templatecompilerbase.php
:656 Stack trace: #0 E:\xampp\htdocs\MyProject\libs\smarty\sysplugins
\smarty_internal_compile_private_special_variable.php
 (93): Smarty_Internal_TemplateCompilerBase-
 >trigger_template_error('$smarty.configL...') 
#1 E:\xampp\htdocs\MyProject\libs\smarty\sysplugins
\smarty_internal_templatecompilerbase.php
(473): Smarty_Internal_Compile_Private_Special_Variable
->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), 
'['configLoad']', NULL, NULL) 
#2 E:\xampp\htdocs\MyProject\libs\smarty\sysplugins
\smarty_internal_templatecompilerbase.php
(247): Smarty_Internal_TemplateCompilerBase
->callTagCompiler('private_special...', Array
, '['configLoad']') #3 E:\xampp\htdocs\Cel 
in E:\xampp\htdocs\Project\libs\smarty\sysplugins
\smarty_internal_templatecompilerbase.php on line 656

config.php就是这个......

define ( 'SITE_ROOT', dirname ( dirname ( __FILE__ ) ) );
define ( 'PRESENTATION_DIR', SITE_ROOT . '/presentation/' );
define ( 'BUSINESS_DIR', SITE_ROOT . '/business/' );
define ( 'SMARTY_DIR', SITE_ROOT . '/libs/smarty/' );
define ( 'TEMPLATE_DIR', PRESENTATION_DIR . 'templates' );
define ( 'COMPILE_DIR', PRESENTATION_DIR . 'templates_c' );
define ( 'CONFIG_DIR', '/include/configs' );

application.php就是这个......

require_once SMARTY_DIR . 'Smarty.class.php';

class Application extends Smarty {
public function __construct() {
parent::__construct ();

    $this->template_dir = TEMPLATE_DIR;
    $this->compile_dir = COMPILE_DIR;
    $this->config_dir = CONFIG_DIR;
}

}

,这是我的index.php ...

require_once 'include/config.php';

require_once PRESENTATION_DIR . 'application.php';

$application = new Application ();

$application->display ( 'test.tpl' );

我正在使用PHP 5.4.16和smarty 3.1.10

非常感谢任何建议。

1 个答案:

答案 0 :(得分:3)

$smarty->configLoad('site.conf')转到你的application.php而不是模板文件。

如果您在.tpl文件中使用此功能,可以这样做

{config_load file="site.conf"}

参考:http://www.smarty.net/docsv2/en/language.function.config.load.tpl

修改 检查路径是否正确。试试

{config_load file="../../configs/site.conf"}