Static pages

Note: This tutorial assumes you’ve downloaded CodeIgniter and installed the framework in your development environment. The first thing you’re going to do is set up a controller to handle static pages. A controller is simply a class that helps delegate work. It is the glue of your web application. For example, when a call is made to: http://example.com/news/latest/10 We might imagine that there is a controller named “news”. The method being called on news would be “latest”. The news method’s

standard_date()

standard_date([$fmt = 'DATE_RFC822'[, $time = NULL]]) Parameters: $fmt (string) – Date format $time (int) – UNIX timestamp Returns: Formatted date or FALSE on invalid format Return type: string Lets you generate a date string in one of several standardized formats. Example: $format = 'DATE_RFC822'; $time = time(); echo standard_date($format, $time); Note This function is DEPRECATED. Use the native date() combined with DateTime’s format constants instead: echo date(DATE_RFC822, ti

smiley_js()

smiley_js([$alias = ''[, $field_id = ''[, $inline = TRUE]]]) Parameters: $alias (string) – Field alias $field_id (string) – Field ID $inline (bool) – Whether we’re inserting an inline smiley Returns: Smiley-enabling JavaScript code Return type: string Generates the JavaScript that allows the images to be clicked and inserted into a form field. If you supplied an alias instead of an id when generating your smiley links, you need to pass the alias and corresponding form id into the

site_url()

site_url([$uri = ''[, $protocol = NULL]]) Parameters: $uri (string) – URI string $protocol (string) – Protocol, e.g. ‘http’ or ‘https’ Returns: Site URL Return type: string Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, plus the url_suffix as set in your config file. You are encouraged to use this function a

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'

show_error()

show_error($message, $status_code, $heading = 'An Error Was Encountered') Parameters: $message (mixed) – Error message $status_code (int) – HTTP Response status code $heading (string) – Error page heading Return type: void This function will display the error message supplied to it using the error template appropriate to your execution: application/views/errors/html/error_general.php or: application/views/errors/cli/error_general.php The optional parameter $status_code determine

show_404()

show_404($page = '', $log_error = TRUE) Parameters: $page (string) – URI string $log_error (bool) – Whether to log the error Return type: void This function will display the 404 error message supplied to it using the error template appropriate to your execution: application/views/errors/html/error_404.php or: application/views/errors/cli/error_404.php The function expects the string passed to it to be the file path to the page that isn’t found. The exit status code will be set to

set_value()

set_value($field[, $default = ''[, $html_escape = TRUE]]) Parameters: $field (string) – Field name $default (string) – Default value $html_escape (bool) – Whether to turn off HTML escaping of the value Returns: Field value Return type: string Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a default value for the form. The third (optional) parameter

set_status_header()

set_status_header($code[, $text = '']) Parameters: $code (int) – HTTP Reponse status code $text (string) – A custom message to set with the status code Return type: void Permits you to manually set a server status header. Example: set_status_header(401); // Sets the header as: Unauthorized See here for a full list of headers.

set_select()

set_select($field[, $value = ''[, $default = FALSE]]) Parameters: $field (string) – Field name $value (string) – Value to check for $default (string) – Whether the value is also a default one Returns: ‘selected’ attribute or an empty string Return type: string If you use a <select> menu, this function permits you to display the menu item that was selected. The first parameter must contain the name of the select menu, the second parameter must contain the value of each item,