Smarty исключение: «Пожалуйста, используйте parent :: __ construct () для вызова родительского конструктора» - PullRequest
3 голосов
/ 10 июня 2011

Я следую учебному пособию и после настройки все получаю:

Неустранимая ошибка: необработанное исключение «SmartyException» с сообщением «Пожалуйста, используйте parent :: __ construct () для вызова родительского конструктора '

Это мой конфигурационный файл:

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

Как я могу исправить эту ошибку?

Ответы [ 3 ]

7 голосов
/ 10 июня 2011

Это означает, что существует класс, расширяющий класс Smarty, который использует метод __construct, который должен содержать что-то вроде:

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

, это вызовет метод конструкции smarty, который выглядит примерно так:

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']);
    } 
} 
3 голосов
/ 10 июня 2011

Из ваших комментариев ваш конструктор класса Application должен вызывать 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;
    }

}

?>
1 голос
/ 10 января 2013

эта ссылка будет полезна.Конструктор this-> Smarty () распознается PHP4, а родительский :: __ construct () - PHP5.Ошибка возникает при использовании this-> Smarty () в PHP5.

...