Created
April 16, 2015 04:17
-
-
Save darkoverlordofdata/b208f5efd223a8631d88 to your computer and use it in GitHub Desktop.
CodeIgniter - Custom Loader using layouts
This file contains hidden or 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 | |
/** | |
* CodeIgniter - Custom Loader using layouts | |
* | |
* @author darkoverlordofdata | |
*/ | |
class MY_Loader extends CI_Loader { | |
var $layout = ''; | |
const EXT = '.phtml'; | |
/** | |
* Get the default layout view | |
*/ | |
function __construct() { | |
parent::__construct(); | |
$layout = config_item('layout'); | |
if ($layout <> '') { | |
$this->layout = $layout.self::EXT; | |
} | |
} | |
/** | |
* Change the layout view | |
* | |
* @param type $layout | |
*/ | |
function setLayout($layout) { | |
$this->layout = $layout.self::EXT; | |
} | |
/** | |
* Render the view with layout | |
* | |
* @param string $view | |
* @param array $view_data | |
* @param boolean $return | |
* @return string | |
*/ | |
function view($view = '' , $view_data = array(), $return = FALSE) { | |
if ($view <> '') { | |
$view = $view.self::EXT; | |
} | |
if ($this->layout <> '') { | |
$view_data['content'] = parent::view($view, $view_data, TRUE); | |
return parent::view($this->layout, $view_data, $return); | |
} else { | |
return parent::view($view, $view_data, $return); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment