0

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

我的项目

->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

任何建议都受到高度赞赏。

4

1 回答 1

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"}
于 2013-07-30T19:13:26.267 回答