Merged in bugfix/PMC-1216 (pull request #7080)

PMC-1216

Approved-by: Paula Quispe <paula.quispe@processmaker.com>
Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Julio Cesar Laura Avendaño
2019-09-18 18:38:03 +00:00

View File

@@ -1,34 +1,59 @@
<?php
namespace Maveriks\Pattern\Mvc;
use Maveriks\Util\Common;
use Smarty;
class SmartyView extends View
{
/**
* @var Smarty class instance
*/
protected $smarty;
/**
* Class constructor
*
* @param string $tpl
*/
public function __construct($tpl = '')
{
// Call the parent constructor
parent::__construct($tpl);
require_once PATH_THIRDPARTY . 'smarty/libs/Smarty.class.php'; //
$this->smarty = new \Smarty();
$this->smarty->compile_dir = defined('PATH_SMARTY_C')? PATH_SMARTY_C : sys_get_temp_dir();
$this->smarty->cache_dir = defined('PATH_SMARTY_CACHE')? PATH_SMARTY_CACHE : sys_get_temp_dir();
// Instance Smarty class
$this->smarty = new Smarty();
if (! is_dir($this->smarty->compile_dir)) {
// Set Smarty temporal paths
$this->smarty->compile_dir = defined('PATH_SMARTY_C') ? PATH_SMARTY_C : sys_get_temp_dir();
$this->smarty->cache_dir = defined('PATH_SMARTY_CACHE') ? PATH_SMARTY_CACHE : sys_get_temp_dir();
// If the paths don't exist we need to create them
if (!is_dir($this->smarty->compile_dir)) {
Common::mk_dir($this->smarty->compile_dir);
}
if (! is_dir($this->smarty->cache_dir)) {
if (!is_dir($this->smarty->cache_dir)) {
Common::mk_dir($this->smarty->cache_dir);
}
}
public function assign($name, $value)
/**
* Assign a value to a Smarty piece in the template
*
* @param string $name
* @param mixed $value
*
* @return void
*/
public function assign($name, $value = null)
{
$this->smarty->assign($name, $value);
}
/**
* Render the Smarty template
*/
public function render()
{
$this->smarty->display($this->getTpl());