smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.26k stars 712 forks source link

upgrade smarty 4 for smarty 5 (load & extend class) #1082

Closed gtraxx closed 5 days ago

gtraxx commented 5 days ago

I upgrade my smarty 4 version to smarty 5 but the structure is completely different and I don't understand anything to adapt my current code (my class which extends). I load the file libs/Smarty.class.php and it doesn't work at all, even by modifying the folder link which I find quite particular after using composer (see my capture)

<?php
/**
 * Extend class smarty
 *
 */
class frontend_model_smarty extends Smarty{
    /**
    * Variable statique permettant de porter l'instance unique
    */
    static protected $instance;
    protected $template;
    /**
     * function construct class
     *
     */
    public function __construct($t){
        /**
         * include parent var smarty
         */
        parent::__construct(); 
        self::setParams($t);
        /*
         You can remove this comment, if you prefer this JSP tag style
         instead of the default { and }
         $this->left_delimiter =  '<%';
         $this->right_delimiter = '%>';
         */
    }
    private function setPath(){
        return component_core_system::basePath();
    }

    /**
     * @param $t
     * @return void
     * @throws SmartyException
     */
    protected function setParams($t = null){
        $template = $t instanceof frontend_model_template ? $t : new frontend_model_template();

        /**
         * Path -> configs
         */
        $this->setConfigDir(array(
            self::setPath()."locali18n/",
            self::setPath() . "skin/" . $template->theme . '/i18n/'
        ));
        /**
         * additionnal Path -> configs
         */
        /**
         * Path -> templates
         */
        $this->setTemplateDir(array(
            self::setPath()."skin/".$template->theme.'/'
        ));

        /**
         * path plugins
         * @var void
         */
        $this->setPluginsDir(array(
            self::setPath().'lib/smarty4/plugins/'
            ,self::setPath().'app/wdcore/'
            ,self::setPath().'widget/'
        ));
        /**
         * Ajout du dossier additionnels des plugins smarty dans le template courant
         */
        $template->addWidgetDir(
            $this,
            self::setPath(),
            false
        );
        /**
         * Path -> compile
         */
        $this->setCompileDir(
            self::setPath().'var/templates_c/'
        );
        /**
         * debugging (true/false)
         */
        $this->debugging = false;
        /**
         * compile (true/false)
         */
        $this->compile_check = true;
        $this->config_booleanize = false;
        /**
         * Force compile
         * @var void
         * (true/false)
         */
        $this->force_compile = false;
        /**
         * caching (true/false)
         */
        $template->setCache($this);

        /**
         * Use sub dirs (true/false)
         */
        $this->use_sub_dirs = false;
        /**
         * cache_dir -> cache
         */
        $this->setCacheDir(
            self::setPath().'var/tpl_caches/'
        );
        /**
         * load pre filter
         */
        $this->loadFilter('output', 'trimwhitespace');
        $this->loadPlugin('smarty_compiler_switch');
        /**
         * 
         * @var error_reporting
         */
        $this->error_reporting = error_reporting() &~E_NOTICE;
    }
    public static function getInstance($t = null){
        if (!isset(self::$instance))
      {
         self::$instance = new frontend_model_smarty($t);
      }
        return self::$instance;
    }
}
?>
Capture d’écran 2024-11-20 à 16 57 00
wisskid commented 5 days ago

Please read https://smarty-php.github.io/smarty/stable/upgrading/, particularly the part about namespaces.