From the beginning of the project we have been making use of the Smarty templating engine and although Phalcon has its own (Volt) due to the team being used to Smarty and in my opinion Smarty being more powerful we have opted to continue with it.
In order to integrate Smarty into Phalcon we customised the class that incubator created it can be retrieved here . This class extends the Engine class from Phalcon which later uses dependency injection to integrate Smarty into Phalcon,
So now that we have that class integrated we need to make use of it. In our public folder of Phalcon we setup a kernel file for each one of our sites.
require dirname(__DIR__) . "/configuration.php";
* Read the configuration
$config = include WEBS_DIR . "/config/config.php";
* Read auto-loader
include WEBS_DIR . "/config/loader.php";
* Read services
* @var \Phalcon\Di $di
include WEBS_DIR . "/config/services.php";
* Read services
include WEBS_DIR . "/config/routes.php";
* Handle the request
$application = new \Phalcon\Mvc\Application($di);
// Register the installed modules
'website' => array(
'className' => 'Axxess\Website\Module',
'path' => WEBS_DIR . 'class.Module.php',
catch (\Exception $e)
So now that we have setup our kernel we have to create the Smarty setup in the services.php in out site's folder.
Firstly instantiate the Phalcon dependency injector.
* The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
$di = new FactoryDefault();
then we inject the Smarty engine
$di->set('view', function () use ($config)
$view = new View();
'.tpl' => function(View $view, $di)
$smarty = new SmartyEngine($view, $di);
$smartyInstance = $smarty->getSmarty();
->setCompileDir(WEBS_DIR . 'viewsCompiled' . DS)
->setCacheDir(WEBS_DIR . 'viewsCache' . DS)
->setConfigDir(WEBS_DIR . 'viewsConfigs' . DS)
->addPluginsDir(SMARTY_DIR . 'plugins' . DS . 'axxess' . DS . 'website');
This now allows us to access smarty like we would of Volt in the view variable in the Phalcon controllers.