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 に答える