[eluser]richthegeek[/eluser]
Hi all,
I made a minor modification to the view() function, which makes it easier to loop through a database result set with a seperate view for each.
Here is how I would do it with the vanilla CI view():
Code:
<?php
foreach( $posts->result() as $post ) {
$this->load->view('blog_post', $post);
} ?>
Not too stressfull... but with my mod, it can be simplified to this:
Code:
<?php
$this->load->view('blog_post', $post, false, true);
?>
The 3rd parameter is an existing "return" value, which defaults to false. The fourth is the one I added.
Here is my modified load function: (found in System/libraries/Loader.php):
Code:
function view($view, $vars = array(), $return = FALSE, $loop = FALSE)
{
if( $loop ) {
foreach( $vars as $var ) {
$rt = $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($var), '_ci_return' => $return));
$return .= $rt;
}
return $return;
} else {
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
}
Tell me if you find this useful - I sure do...