Skip to content

Instantly share code, notes, and snippets.

@puneetkay
Last active December 31, 2015 18:59
Show Gist options
  • Save puneetkay/8031039 to your computer and use it in GitHub Desktop.
Save puneetkay/8031039 to your computer and use it in GitHub Desktop.
Get current controller and method in CI. Also, technique to get/manage dynamic global vars
<?php
class CI_Controller {
private static $instance;
public $data = array();
/**
* Constructor
*/
public function __construct()
{
self::$instance =& $this;
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class);
}
$this->load =& load_class('Loader', 'core');
$this->load->initialize();
//$this->doSomething(); // Preprocessing on all controllers.
$this->data['controller'] = $this->router->fetch_class();
$this->data['current'] = $this->router->fetch_method();
log_message('debug', "Controller Class Initialized");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment