Hooks - Extending the Framework Core

CodeIgniter’s Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files. When CodeIgniter runs it follows a specific execution process, diagramed in the Application Flow page. There may be instances, however, where you’d like to cause some action to take place at a particular stage in the execution process. For example, you might want to run a script right before your controllers get loaded, or right after, or you might want to trig

CI_Benchmark::elapsed_time()

elapsed_time([$point1 = ''[, $point2 = ''[, $decimals = 4]]]) Parameters: $point1 (string) – a particular marked point $point2 (string) – a particular marked point $decimals (int) – number of decimal places for precision Returns: Elapsed time Return type: string Calculates and returns the time difference between two marked points. If the first parameter is empty this function instead returns the {elapsed_time} pseudo-variable. This permits the full system execution time to be show

CI_Cache::increment()

increment($id[, $offset = 1]) Parameters: $id (string) – Cache ID $offset (int) – Step/value to add Returns: New value on success, FALSE on failure Return type: mixed Performs atomic incrementation of a raw stored value. // 'iterator' has a value of 2 $this->cache->increment('iterator'); // 'iterator' is now 3 $this->cache->increment('iterator', 3); // 'iterator' is now 6

CI_Cache::is_supported()

is_supported($driver) Parameters: $driver (string) – the name of the caching driver Returns: TRUE if supported, FALSE if not Return type: bool This method is automatically called when accessing drivers via $this->cache->get(). However, if the individual drivers are used, make sure to call this method to ensure the driver is supported in the hosting environment. if ($this->cache->apc->is_supported()) { if ($data = $this->cache->apc->get('my_cache'))

CI_Cache::delete()

delete($id) Parameters: $id (string) – name of cached item Returns: TRUE on success, FALSE on failure Return type: bool This method will delete a specific item from the cache store. If item deletion fails, the method will return FALSE. $this->cache->delete('cache_item_id');

CI_Calendar::initialize()

initialize([$config = array()]) Parameters: $config (array) – Configuration parameters Returns: CI_Calendar instance (method chaining) Return type: CI_Calendar Initializes the Calendaring preferences. Accepts an associative array as input, containing display preferences.

CI_Config::item()

item($item[, $index='']) Parameters: $item (string) – Config item name $index (string) – Index name Returns: Config item value or NULL if not found Return type: mixed Fetch a config file item.

CI_Email::set_alt_message()

set_alt_message($str) Parameters: $str (string) – Alternative e-mail message body Returns: CI_Email instance (method chaining) Return type: CI_Email Sets the alternative e-mail message body: $this->email->set_alt_message('This is the alternative message'); This is an optional message string which can be used if you send HTML formatted email. It lets you specify an alternative message with no HTML formatting which is added to the header string for people who do not accept HTML

CI_Email::message()

message($body) Parameters: $body (string) – E-mail message body Returns: CI_Email instance (method chaining) Return type: CI_Email Sets the e-mail message body: $this->email->message('This is my message');

CI_Encrypt::encode_from_legacy()

encode_from_legacy($string[, $legacy_mode = MCRYPT_MODE_ECB[, $key = '']]) Parameters: $string (string) – String to encrypt $legacy_mode (int) – Valid PHP MCrypt cipher constant $key (string) – Encryption key Returns: Newly encrypted string Return type: string Enables you to re-encode data that was originally encrypted with CodeIgniter 1.x to be compatible with the Encrypt library in CodeIgniter 2.x. It is only necessary to use this method if you have encrypted data stored permane