Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /**
- * MY_Template
- *
- * @package MY_Template
- * @author mk
- * @copyright 2011
- * @version 1.0
- * @access public
- */
- class MY_Template {
- private $CI;
- private $layout;
- private $partials = array();
- private $destinations = array();
- function __construct() {
- $this->CI =& get_instance();
- }
- /**
- * MY_Template::set_layout()
- *
- * Define el view para el layout
- *
- * @param string $layout
- * @return void
- */
- public function set_layout($layout) {
- $this->layout = $layout;
- }
- /**
- * MY_Template::set_view()
- *
- * Escribir un View en una zona del template
- *
- * @param string $destination
- * @param string $view_name
- * @param array $view_data
- * @return void
- */
- public function set_view($destination = null, $view_name = null, $view_data = array()) {
- if (isset($destination) && isset($view_name)) {
- $this->partials[] = array(
- "type" => "view",
- "destination" => $destination,
- "view_name" => $view_name,
- "view_data" => $view_data
- );
- } else {
- show_error("Destination y View Name deben ser especificados");
- }
- }
- /**
- * MY_Template::set_value()
- *
- * Escribir un valor en una zona del template
- *
- * @param string $destination
- * @param mixed $value
- * @return void
- */
- public function set_value($destination = null, $value = null) {
- if (isset($destination) && isset($value)) {
- $this->partials[] = array(
- "type" => "value",
- "destination" => $destination,
- "value" => $value
- );
- } else {
- show_error("Destination y Value deben ser especificados");
- }
- }
- /**
- * MY_Template::render()
- *
- * Renderear el layout con todos los Views y valores escritos
- *
- * @param bool $return
- * @return void
- */
- public function render($return = false) {
- foreach ($this->partials as $partial) {
- switch ($partial['type']) {
- case "view":
- $this->destinations[$partial['destination']] = $this->CI->load->view($partial['view_name'], $partial['view_data'], true);
- break;
- case "value":
- $this->destinations[$partial['destination']] = $partial['value'];
- break;
- }
- }
- if ($return) {
- return($this->CI->load->view($this->layout, array(), true));
- } else {
- $this->CI->load->view($this->layout);
- }
- }
- /**
- * MY_Template::get()
- *
- * Obtener un View rendereado o un valor para escribirlo en el layout
- *
- * @param string $destination
- * @return
- */
- public function get($destination) {
- if (isset($this->destinations[$destination])) {
- return($this->destinations[$destination]);
- } else {
- return("");
- }
- }
- public function __get($destination) {
- if (isset($this->destinations[$destination])) {
- return($this->destinations[$destination]);
- } else {
- return("");
- }
- }
- public function __set($destination = null, $value = null) {
- if (isset($destination) && isset($value)) {
- $this->destinations[$destination] = $value;
- } else {
- show_error("Destination y Value deben ser especificados");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement