D
D
Dmitry Vyatkin2015-04-06 16:52:46
PHP
Dmitry Vyatkin, 2015-04-06 16:52:46

How to properly set up default directories in Smarty templating class?

Hello! Faced such a problem. I downloaded the Smarty templating engine via Composer and I can't configure default directories in the class. Composer wrote smarty files to the vendor folder, when connecting "require_once 'vendor/autoload'" everything works. Next, I created three folders in the root directory of the website, as indicated in the instructions on the smarty site, but when I create my own file in which I inherit the Smarty class and then include this file in index.php, via "require_once 'views/application.php '" then nothing happens. If you specify the path to autoload in index.php and assign directories, then the file with templates from the templates folder is loaded. The site root directory is the root directory of the web server.
Here is the content of my file called application.php:

<?php
// Ссылка на библиотеку Smarty
require_once 'vendor/autoload.php';
/* Класс, расширяющий Smarty, используется для обработки и
отображения файлов Smarty */
class Application extends Smarty
{
// Конструктор класса
public function __construct()
{
// Вызов конструктора Smarty
parent::Smarty();
// Меняем папки шаблонов по умолчанию
$this->template_dir = 'views/templates';
$this->compile_dir = 'views/templates_c';
$this->config_dir = 'configs';
}
}
?>

And this is the content of the index.php file:
<?php
require_once 'views/application.php';
$application = new Application();
$application->display('main.tpl');

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question