DevHow: Code Snippets from all around

CodeIgniter get_instance helper

URL: http://codeigniter.com/forums/viewthread/111108/

Tag(s): Codeigniter

A nice function if you're tired of typing '$ci =& get_instance();' or similar.

// Add to a helper and load it from your controller
function CI() {
    if (!function_exists('get_instance')) exit('ERROR! : ' . __FILE__ .':'. __FUNCTION__ . ":: Can't get Code Igniter instance. Are you calling this function from within your application?");

    $ci =& get_instance();
    return $ci;
}

// Example
<?=CI()->buildBreadcrumb()?>

Comments

You must be logged in to comment