News section

In the last section, we went over some basic concepts of the framework by writing a class that includes static pages. We cleaned up the URI by adding custom routing rules. Now it’s time to introduce dynamic content and start using a database. Setting up your model Instead of writing database operations right in the controller, queries should be placed in a model, so they can easily be reused later. Models are the place where you retrieve, insert, and update information in your database or other

CI_Pagination::initialize()

initialize([$params = array()]) Parameters: $params (array) – Configuration parameters Returns: CI_Pagination instance (method chaining) Return type: CI_Pagination Initializes the Pagination class with your preferred options.

Profiling Your Application

The Profiler Class will display benchmark results, queries you have run, and $_POST data at the bottom of your pages. This information can be useful during development in order to help with debugging and optimization. Initializing the Class Important This class does NOT need to be initialized. It is loaded automatically by the Output Library if profiling is enabled as shown below. Enabling the Profiler To enable the profiler place the following line anywhere within your Controller methods: $t

CI_DB_utility::repair_table()

repair_table($table_name) Parameters: $table_name (string) – Name of the table to repair Returns: Array of repair messages or FALSE on failure Return type: array Repairs a database table.

CI_DB_result::num_fields()

num_fields() Returns: Number of fields in the result set Return type: int Returns the number of fields in the result set. Usage: see Result Helper Methods.

PHP Style Guide

The following page describes the coding styles adhered to when contributing to the development of CodeIgniter. There is no requirement to use these styles in your own CodeIgniter application, though they are recommended. Table of Contents PHP Style Guide File FormatTextMate BBEdit PHP Closing Tag File Naming Class and Method Naming Variable Names Commenting Constants TRUE, FALSE, and NULL Logical Operators Comparing Return Values and Typecasting Debugging Code Whitespace in Files Compatibilit

Connecting to your Database

There are two ways to connect to a database: Automatically Connecting The “auto connect” feature will load and instantiate the database class with every page load. To enable “auto connecting”, add the word database to the library array, as indicated in the following file: application/config/autoload.php Manually Connecting If only some of your pages require database connectivity you can manually connect to your database by adding this line of code in any function where it is needed, or in your

CI_Loader::clear_vars()

clear_vars() Returns: CI_Loader instance (method chaining) Return type: CI_Loader Clears cached view variables.

CI_Input

class CI_Input $raw_input_stream Read only property that will return php://input data as is. The property can be read multiple times. post([$index = NULL[, $xss_clean = NULL]]) Parameters: $index (mixed) – POST parameter name $xss_clean (bool) – Whether to apply XSS filtering Returns: $_POST if no parameters supplied, otherwise the POST value if found or NULL if not Return type: mixed The first parameter will contain the name of the POST item you are looking for: $this->i

Controllers

Controllers are the heart of your application, as they determine how HTTP requests should be handled. Page Contents ControllersWhat is a Controller? Let’s try it: Hello World! Methods Passing URI Segments to your methods Defining a Default Controller Remapping Method Calls Processing Output Private methods Organizing Your Controllers into Sub-directories Class Constructors Reserved method names That’s it! What is a Controller? A Controller is simply a class file that is named in a way that