$this in CodeIgniter is effectively a God-like object. In one of my projects which is rather mature and large-ish, I tried to print its payload and crashed my app (with a fatal error that I can't remember).
$this is available in all Controllers, Models, and Views. In any layer where you don't have immediate access to $this as the CI instance (such as a library class or helper function), it is common practice to declare $ci = get_instance(); (or $CI). Depending on your extension of the core classes, the instance might refer to CI_Controller or MY_Controller.
In a library, it may be most beneficial to declare $this->CI in your constructor.
public function __construct()
{
/* @var MY_Controller $CI */
$this->CI = get_instance();
}
In a helper function (my understanding is that helpers are never built inside of classes):
/* @var MY_Controller $CI */
$CI = get_instance();
Some facts about "config" data:
$this->config->item() and config_item() both require at least one parameter.
get_config() does not require a parameter and will contain the entire config payload. When I tested, I found the following first level properties in the object: config, is_loaded, and _config_paths.
- When you use
$this->config->item() to access a value by a specified key, if that key doesn't exist, the returned value will be null.
- When you have a multidimensional array held in your config array, you can directly access a second-level value by nominating two parameters in the
$this->config->item() call. Counterintuitively, the first parameter will be the second level key and the second parameter is the first level key.
$this->config->item('childKey', 'parentKey');
If looking to extend your CodeIgniter-fu, you might be enlightened by the ability to observe loaded libraries, helpers, and models. How to list all loaded libraries and helpers in a CodeIgniter application?