This commit is contained in:
Julio Cesar Laura Avendaño
2019-09-18 12:49:28 -04:00
parent 4ee6d7ce2d
commit 78f61a06ab

View File

@@ -1,34 +1,59 @@
<?php <?php
namespace Maveriks\Pattern\Mvc; namespace Maveriks\Pattern\Mvc;
use Maveriks\Util\Common; use Maveriks\Util\Common;
use Smarty;
class SmartyView extends View class SmartyView extends View
{ {
/**
* @var Smarty class instance
*/
protected $smarty; protected $smarty;
/**
* Class constructor
*
* @param string $tpl
*/
public function __construct($tpl = '') public function __construct($tpl = '')
{ {
// Call the parent constructor
parent::__construct($tpl); parent::__construct($tpl);
require_once PATH_THIRDPARTY . 'smarty/libs/Smarty.class.php'; //
$this->smarty = new \Smarty(); // Instance Smarty class
$this->smarty->compile_dir = defined('PATH_SMARTY_C')? PATH_SMARTY_C : sys_get_temp_dir(); $this->smarty = new Smarty();
$this->smarty->cache_dir = defined('PATH_SMARTY_CACHE')? PATH_SMARTY_CACHE : sys_get_temp_dir();
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); 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); 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); $this->smarty->assign($name, $value);
} }
/**
* Render the Smarty template
*/
public function render() public function render()
{ {
$this->smarty->display($this->getTpl()); $this->smarty->display($this->getTpl());