Created
November 11, 2010 20:20
-
-
Save justincampbell/673103 to your computer and use it in GitHub Desktop.
Mark Huot's Loader class for CI. Supports layouts. http://bitbucket.org/markhuot/codeigniter/src/tip/application/core/MY_Loader.php
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 | |
class MY_Loader extends CI_Loader { | |
/** | |
* Load View With Layout | |
* http://bitbucket.org/markhuot/codeigniter/src/tip/application/core/MY_Loader.php | |
* This function is used to load a "view" file inside the specified layout. It has four parameters: | |
* | |
* 1. The name of the "layout" file to be included. | |
* 1. The name of the "view" file to be included. | |
* 2. An associative array of data to be extracted for use in the view. | |
* 3. TRUE/FALSE - whether to return the data or load it. In | |
* some cases it's advantageous to be able to return data so that | |
* a developer can process it in some way. | |
* | |
* @access public | |
* @param string | |
* @param array | |
* @param bool | |
* @return void | |
*/ | |
function view_with_layout($view='', $vars = array(), $return = FALSE, $layout=null) | |
{ | |
$ci =& get_instance(); | |
if ($layout === null) | |
{ | |
$backtrace = debug_backtrace(); | |
$layout_file = strtolower($backtrace[1]['class']); | |
if (isset($ci->layout)) | |
{ | |
$layout = $ci->layout; | |
} | |
else if(file_exists(APPPATH.'views/layouts/'.$layout_file.EXT)) | |
{ | |
$layout = $layout_file; | |
} | |
else if(file_exists(APPPATH.'views/layouts/application'.EXT)) | |
{ | |
$layout = 'application'; | |
} | |
else | |
{ | |
$layout = false; | |
} | |
} | |
if ($layout === FALSE) | |
{ | |
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); | |
} | |
$vars['yield'] = $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => TRUE)); | |
return $this->_ci_load(array('_ci_view' => 'layouts/'.$layout, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); | |
} | |
// -------------------------------------------------------------------- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment