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'); } } 
  • where did you inherit in the second controller? yes, the correct behavior, but it makes sense to put the initialization of the smarti into a separate method and call it later. and connect php files somewhere inside the methods is not good. The names of directories are better to pull into the config. - teran
  • and in general, make sure that the final controller does not know about the presence of smarti. make the basic display() method that will call smarti. and set to set variables - teran

0