Unable to register extension “*” as extensions have already been initialized

393
23 мая 2017, 04:53

При загрузке Extension в Twig, происходит ошибка Unable to register extension "SectionParser" as extensions have already been initialized.

Код Extension'a

class Twig_Extension_SectionParser extends Twig_Extension {
    public $_sectionInfos;
    public function __construct($sectionInfos)
    {
        $this->_sectionInfos = $sectionInfos;
    }
    public function getTokenParsers()
    {
        return array(new Twig_TokenParser_Section($this->_sectionInfos));
    }
    public function getFilters()
    {
        return array();
    }
    public function getName()
    {
        return 'SectionParser';
    }
}

Сам класс обработки шаблонов

class scTemplateParser extends miTemplateParser { 
........
public function __construct()
    {
        unset($this->_twig);
        $this->_skin = scSkins::singleton()->getCurrentSkin();
        $loader = new Twig_Loader_Filesystem($this->_skin->getSkinPath());
        $this->_twig = new Twig_Environment($loader, array(
            //'cache' => $_SERVER['DOCUMENT_ROOT'] . '/userfiles/cache/twig/',
            'auto_reload' => true,
            'debug' => $this->_twigDebug,
        ));
        $functionCount = new Twig_SimpleFunction('count', array($this, 'countArratTwig'));
        $this->_twig->addExtension(new Twig_Extensions_Extension_I18n());
        $this->_twig->addExtension(new Twig_Extension_Debug());
        $this->_twig->addFunction($functionCount);
    }
 ....
 public function templateParse()
    {
        // Summer Cart modifications
        $this->assignSystemVariables();
        scHooks::action('sc.template.before-parse', $this->_templateFileName, $this);
        //var_dump($this->_twig->getExtensions());
        if ($this->_twigEnabled) {
            $sectionParser = new Twig_Extension_SectionParser($this->_sectionInfos);
            $this->_twig->addExtension($sectionParser);
            $this->_twigTemplate = $this->_twig->load($this->_templateFileName);
            $argsForTemplate = $this->getAssignVarsFromTwig();
            $argsForSection = $this->getVarsForSection();
            $args = array_merge($argsForTemplate, $argsForSection);
            return $this->_twigTemplate->render($args);
        } else {
            $preprocessedSections = $this->preprocessTemplateSections($this->_templateSections);
            $html = $this->templateParseSubsection($preprocessedSections, $this->_sectionInfos, 0, $this->_templateVars);
            return self::postprocessTemplate(str_replace(array_keys($this->_templateVars), $this->_templateVars, $html));
        }
    }
}

Самое интересное что когда я переношу код загрузки Extension'a в конструктор, то он нормально работает.

READ ALSO
Как сделать в yii2 консольное обращение

Как сделать в yii2 консольное обращение

Как сделать в Yii2 консольное обращение? Господа прошу подсказать

284
Не работает запрос mysql

Не работает запрос mysql

Не работает этот запросВ phpmyadmin сам запрос дает результат, таблица обновляется, но когда я запускаю php-скрипт работать не хочет

305
Дерево. Рекурсия. Хитрое перемножение

Дерево. Рекурсия. Хитрое перемножение

ЗдравствуйтеДелаю небольшой студенческий проект и у меня возникла трудность которую я не могу разрешить без сторонней помощи

286
mod rewrite в папке

mod rewrite в папке

Есть url вида

220