Created
January 14, 2014 13:21
-
-
Save juniorb2ss/8418206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Smarty Class | |
* | |
* @package CodeIgniter | |
* @subpackage Libraries | |
* @category Smarty | |
* @author Kepler Gelotte | |
* @link http://www.coolphptools.com/codeigniter-smarty | |
*/ | |
require_once APPPATH . "libraries/SmartyBC.class.php"; | |
class Template extends SmartyBC { | |
private $words; | |
private $_ci; | |
private $views = ''; | |
public $EXT = '.tpl'; | |
function __construct() | |
{ | |
parent::__construct(); | |
try | |
{ | |
/** | |
* get instance ci | |
*/ | |
$this->_ci =& get_instance(); | |
/** | |
* load lang | |
*/ | |
//$this->_ci->lang->load('lang', true); | |
/** | |
* get string url | |
*/ | |
$controller = $this->_ci->uri->segment(1); | |
$method = $this->_ci->uri->segment(2); | |
/** | |
* set template path | |
*/ | |
$this->template_dir = 'local/do/template'; | |
/** | |
* smarty paramms | |
*/ | |
$this->compile_dir = APPPATH.'/compile'; | |
$this->cache_dir = APPPATH.'/cache'; | |
$this->config_dir = APPPATH.'/config'; | |
$this->assign('APPPATH', APPPATH ); | |
$this->assign('BASEPATH', BASEPATH ); | |
$this->assign('path', base_url()); | |
// erro firefox templates/2.0\/ | |
$this->assign('template_path', base_url().'/path/template'); | |
$this->assign('memory_usage', $this->_ci->benchmark->memory_usage()); | |
$this->assign('controller', strtolower($controller)); | |
$this->assign('method', strtolower($method)); | |
/** | |
* Assign CodeIgniter object by reference to CI | |
*/ | |
if ( method_exists( $this, 'assignByRef') ) | |
{ | |
$ci =& get_instance(); | |
$this->assignByRef("ci", $ci); | |
} | |
/** | |
* log debug | |
*/ | |
log_message('debug', "Smarty Class Initialized"); | |
} catch (SmartyException $e) | |
{ | |
show_error($e->getmessage()); | |
} | |
} | |
public function display() | |
{ | |
$this->assign('content', $this->views); | |
parent::display('template.tpl'); | |
} | |
/** | |
* Parse a template using the Smarty engine | |
* | |
* This is a convenience method that combines assign() and | |
* display() into one step. | |
* | |
* Values to assign are passed in an associative array of | |
* name => value pairs. | |
* | |
* If the output is to be returned as a string to the caller | |
* instead of being output, pass true as the third parameter. | |
* | |
* @access public | |
* @param string | |
* @param array | |
* @param bool | |
* @return string | |
*/ | |
function view($template, $data = array(), $return = FALSE) | |
{ | |
try{ | |
$template .= $this->EXT; | |
foreach ($data as $key => $val) | |
{ | |
$this->assign($key, $val); | |
} | |
$this->views .= $this->fetch($template) | |
} catch (SmartyException $e) { | |
show_error($e->getmessage()); | |
} | |
} | |
} | |
/* End of file ci_smarty.php */ | |
/* Location: ./application/libraries/ci_smarty.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Como usar:
$this->template->view('views/menu', array( 'dados' => $dados ) ); // menu.tpl
$this->template->view('views/menu_left', array( 'dados' => $dados ) ); // menu_left.tpl
$this->template->display();
Linha 49: Define a pasta do template, a pasta views devera estar dentro desta pasta.