Alternate PHP Syntax for View Files

If you do not utilize CodeIgniter’s template engine, you’ll be using pure PHP in your View files. To minimize the PHP code in these files, and to make it easier to identify the code blocks it is recommended that you use PHPs alternative syntax for control structures and short tag echo statements. If you are not familiar with this syntax, it allows you to eliminate the braces from your code, and eliminate “echo” statements. Automatic Short Tag Support Note If you find that the syntax described

CI_DB_driver::escape()

escape($str) Parameters: $str (mixed) – The value to escape, or an array of multiple ones Returns: The escaped value(s) Return type: mixed Escapes input data based on type, including boolean and NULLs.

CI_DB_query_builder::insert()

insert([$table = ''[, $set = NULL[, $escape = NULL]]]) Parameters: $table (string) – Table name $set (array) – An associative array of field/value pairs $escape (bool) – Whether to escape values and identifiers Returns: TRUE on success, FALSE on failure Return type: bool Compiles and executes an INSERT statement.

directory_map()

directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]]) Parameters: $source_dir (string) – Path to the source directory $directory_depth (int) – Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) $hidden (bool) – Whether to include hidden directories Returns: An array of files Return type: array Examples: $map = directory_map('./mydirectory/'); Note Paths are almost always relative to your main index.php file. Sub-folders contained within

form_radio()

form_radio([$data = ''[, $value = ''[, $checked = FALSE[, $extra = '']]]]) Parameters: $data (array) – Field attributes data $value (string) – Field value $checked (bool) – Whether to mark the radio button as being checked $extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string Returns: An HTML radio input tag Return type: string This function is identical in all respects to the form_checkbox() function above except that it uses the “radio

CI_Input::is_ajax_request()

is_ajax_request() Returns: TRUE if it is an Ajax request, FALSE if not Return type: bool Checks to see if the HTTP_X_REQUESTED_WITH server header has been set, and returns boolean TRUE if it is or FALSE if not.

CI_Cache::get()

get($id) Parameters: $id (string) – Cache item name Returns: Item value or FALSE if not found Return type: mixed This method will attempt to fetch an item from the cache store. If the item does not exist, the method will return FALSE. $foo = $this->cache->get('my_cached_item');

singular()

singular($str) Parameters: $str (string) – Input string Returns: A singular word Return type: string Changes a plural word to singular. Example: echo singular('dogs'); // Prints 'dog'

form_open()

form_open([$action = ''[, $attributes = ''[, $hidden = array()]]]) Parameters: $action (string) – Form action/target URI string $attributes (array) – HTML attributes $hidden (array) – An array of hidden fields’ definitions Returns: An HTML form opening tag Return type: string Creates an opening form tag with a base URL built from your config preferences. It will optionally let you add form attributes and hidden input fields, and will always add the accept-charset attribute based o

CI_Cache::get_metadata()

get_metadata($id) Parameters: $id (string) – Cache item name Returns: Metadata for the cached item Return type: mixed This method will return detailed information on a specific item in the cache. var_dump($this->cache->get_metadata('my_cached_item')); Note The information returned and the structure of the data is dependent on which adapter is being used.