Skip to content

Instantly share code, notes, and snippets.

@darkoverlordofdata
Created April 16, 2015 04:17
Show Gist options
  • Save darkoverlordofdata/b208f5efd223a8631d88 to your computer and use it in GitHub Desktop.
Save darkoverlordofdata/b208f5efd223a8631d88 to your computer and use it in GitHub Desktop.
CodeIgniter - Custom Loader using layouts
<?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