无法在smarty中加载配置文件


Unable to load config file in smarty

我是PHP新手,很聪明,不知道如何解决这个问题。这是关于我的项目目录的一个粗略想法

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文件中定义了一个变量。SITE_TITLE。我正试图在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

如有任何建议,我们将不胜感激。

$smarty->configLoad('site.conf')将转到您的应用程序.php,而不是模板文件。

如果你在.tpl文件中使用这个功能,你可以像这个一样使用

{config_load file="site.conf"}

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

编辑:检查路径是否正确。尝试

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