Models

Models are optionally available for those who want to use a more traditional MVC approach. Page Contents ModelsWhat is a Model? Anatomy of a Model Loading a Model Auto-loading Models Connecting to your Database What is a Model? Models are PHP classes that are designed to work with information in your database. For example, let’s say you use CodeIgniter to manage a blog. You might have a model class that contains functions to insert, update, and retrieve your blog data. Here is an example of

Model-View-Controller

CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting. The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database. The View is the information that is being presented to

meta()

meta([$name = ''[, $content = ''[, $type = 'name'[, $newline = "n"]]]]) Parameters: $name (string) ? Meta name $content (string) ? Meta content $type (string) ? Meta type $newline (string) ? Newline character Returns: HTML meta tag Return type: string Helps you generate meta tags. You can pass strings to the function, or simple arrays, or multidimensional ones. Examples: echo meta('description', 'My Great site'); // Generates: <meta name="description" content="My Great Site"

mdate()

mdate([$datestr = ''[, $time = '']]) Parameters: $datestr (string) – Date string $time (int) – UNIX timestamp Returns: MySQL-formatted date Return type: string This function is identical to PHP’s date() function, except that it lets you use MySQL style date codes, where each code letter is preceded with a percent sign, e.g. %Y %m %d The benefit of doing dates this way is that you don’t have to worry about escaping any characters that are not date codes, as you would normally have t

mb_substr()

mb_substr($str, $start[, $length = NULL[, $encoding = NULL]]) Parameters: $str (string) – Input string $start (int) – Position of first character $length (int) – Maximum number of characters $encoding (string) – Character set Returns: Portion of $str specified by $start and $length or FALSE on failure Return type: string For more information, please refer to the PHP manual for mb_substr().

mb_strpos()

mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]]) Parameters: $haystack (string) – String to search in $needle (string) – Part of string to search for $offset (int) – Search offset $encoding (string) – Character set Returns: Numeric character position of where $needle was found or FALSE if not found Return type: mixed For more information, please refer to the PHP manual for mb_strpos().

mb_strlen()

mb_strlen($str[, $encoding = NULL]) Parameters: $str (string) – Input string $encoding (string) – Character set Returns: Number of characters in the input string or FALSE on failure Return type: string For more information, please refer to the PHP manual for mb_strlen().

Managing your Applications

By default it is assumed that you only intend to use CodeIgniter to manage one application, which you will build in your application/ directory. It is possible, however, to have multiple sets of applications that share a single CodeIgniter installation, or even to rename or relocate your application directory. Renaming the Application Directory If you would like to rename your application directory you may do so as long as you open your main index.php file and set its name using the $applicatio

mailto()

mailto($email, $title = '', $attributes = '') Parameters: $email (string) – E-mail address $title (string) – Anchor title $attributes (mixed) – HTML attributes Returns: A “mail to” hyperlink Return type: string Creates a standard HTML e-mail link. Usage example: echo mailto('[email protected]', 'Click Here to Contact Me'); As with the anchor() tab above, you can set attributes using the third parameter: $attributes = array('title' => 'Mail me'); echo mailto('[email protected]'

log_message()

log_message($level, $message) Parameters: $level (string) – Log level: ‘error’, ‘debug’ or ‘info’ $message (string) – Message to log Return type: void This function lets you write messages to your log files. You must supply one of three “levels” in the first parameter, indicating what type of message it is (debug, error, info), with the message itself in the second parameter. Example: if ($some_var == '') { log_message('error', 'Some variable did not contain a value.'); } els