2011-06-10 22 views
3

我下面的教程,并设置了一切之后,我的:Smarty的例外:“请使用父:: __结构()调用父类的构造”

Fatal error: Uncaught exception 'SmartyException' with message 'Please use parent::__construct() to call parent constuctor'

这是我的配置文件:

<?php 
// SITE_ROOT contains the full path to the tshirtshop folder 
define('SITE_ROOT', dirname(dirname(__FILE__))); 
// Application directories 
define('PRESENTATION_DIR', SITE_ROOT . '/presentation/'); 
define('BUSINESS_DIR', SITE_ROOT . '/business/'); 
// Settings needed to configure the Smarty template engine 
define('SMARTY_DIR', SITE_ROOT . '/libs/smarty/'); 
define('TEMPLATE_DIR', PRESENTATION_DIR . 'templates'); 
define('COMPILE_DIR', PRESENTATION_DIR . 'templates_c'); 
define('CONFIG_DIR', SITE_ROOT . '/include/configs'); 
?> 

我的目录结构是:

mydomain.com/test/include 
mydomain.com/test/libs 
mydomain.com/test/presentation 

我怎样才能解决这个问题?

+0

错误消息是否也不告诉你错误在哪一行? – 2011-06-10 13:10:35

+0

这个PHP4代码是否在PHP5环境中运行? – alex 2011-06-10 13:11:43

+0

不,它是在PHP5环境 – Bob 2011-06-10 13:25:04

回答

7

这意味着有扩展Smarty类是使用__construct需要包含类似方法的类:

public function __construct() { 
    parent::__construct(); 
} 

这将调用它看起来像这样的智者构造方法:

public function __construct() 
{ 
     // selfpointer need by some other class methods 
     $this->smarty = $this; 
    if (is_callable('mb_internal_encoding')) { 
     mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET); 
    } 
    $this->start_time = microtime(true); 
    // set default dirs 
    $this->template_dir = array('.' . DS . 'templates' . DS); 
    $this->compile_dir = '.' . DS . 'templates_c' . DS; 
    $this->plugins_dir = array(SMARTY_PLUGINS_DIR); 
    $this->cache_dir = '.' . DS . 'cache' . DS; 
    $this->config_dir = '.' . DS . 'configs' . DS; 
    $this->debug_tpl = SMARTY_DIR . 'debug.tpl'; 
    if (isset($_SERVER['SCRIPT_NAME'])) { 
     $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); 
    } 
} 
+0

所以我需要改变这里的东西: – Bob 2011-06-10 13:22:07

+0

'<?php //参考Smarty库 require_once SMARTY_DIR。 'Smarty.class.php'; /*类扩展Smarty的,用于处理和显示Smarty的 文件*/ 类应用扩展Smarty的 {// 类构造 公共职能__construct(){ //调用Smarty的构造 父:: Smarty的( ); //更改默认模板目录 $ this-> template_dir = TEMPLATE_DIR; $ this-> compile_dir = COMPILE_DIR; $ this-> config_dir = CONFIG_DIR; }} ?>” – Bob 2011-06-10 13:23:15

+0

对不起,我不能格式化为代码= \ – Bob 2011-06-10 13:23:27

3

根据您的意见,您的应用程序类构造函数需要调用parent::__construct()而不是parent::Smarty()

<?php 

// Reference Smarty library 
require_once SMARTY_DIR . 'Smarty.class.php'; 

/* Class that extends Smarty, used to process and display Smarty files */ 
class Application extends Smarty { 

    // Class constructor 
    public function __construct() { 

     // Call Smarty's constructor 
     // parent::Smarty(); // not this 
     parent::__construct(); // this 

     // Change the default template directories 
     $this->template_dir = TEMPLATE_DIR; 
     $this->compile_dir = COMPILE_DIR; 
     $this->config_dir = CONFIG_DIR; 
    } 

} 

?> 
+0

谢谢,但我已经尝试过了 - 我收到了一条不同的错误消息: 未捕获的异常'SmartyException'带消息'无法加载模板文件'store_front.tpl'' – Bob 2011-06-10 13:50:37

+0

也必须修改配置文件,但它现在工作 - 谢谢 – Bob 2011-06-10 13:56:46

1

这个link将会有帮助。 this-> Smarty()构造函数被PHP5和parent :: __ construct()通过PHP5识别。在PHP5中使用this-> Smarty()时发生错误。