As a practice in PHP, I decided to write a blog.
It is necessary to transfer the Smarty template object to the methods of my classes that are responsible for the generation of pages.
Is this solution correct? In the main controller, with the help of the constructor, we create a smarti object and then inherit the main controller class to other classes?
// Основной контроллер abstract class Controller { protected $smarty; public function __construct() { // Подключение Smarty require_once(SMARTY_DIR . 'Smarty.class.php'); $this->smarty = new Smarty; $this->smarty->template_dir = SMARTY_DIR . 'templates/'; $this->smarty->compile_dir = SMARTY_DIR . 'templates_c/'; $this->smarty->config_dir = SMARTY_DIR . 'configs/'; $this->smarty->cache_dir = SMARTY_DIR . 'cache/'; } } // Контроллер статей class ArticleController { public function indexAction() { // Подключение шаблона статей $this->smarty->display('article.tpl'); } }
display()method that will call smarti. andsetto set variables - teran