CodeIgniter 3 User Guide

repository·develop·Indexed 12 days ago

https://github.com/bcit-ci/codeigniter

Documentation for CodeIgniter 3, a PHP application development framework for PHP 5.6+. This legacy version is in maintenance mode and provides a rich set of libraries for web development, including native form validation rules, database caching, and a flexible routing system via the index.php front controller.

Tokens
141.3K
Snippets
587
Records
723
Agent score
87%

What's inside CodeIgniter

  1. Overview of CodeIgniter core features

    develop

    CodeIgniter is a lightweight web framework designed for high performance and ease of use. Its core feature set includes:

    • Architecture: Model-View-Controller (MVC) based system.
    • Database: Full-featured database classes with Query Builder support for multiple platforms.
    • Security: Built-in Security and XSS filtering, Data Encryption, and Session Management.
    • Data Handling: Form and Data Validation, File Uploading, and Zip Encoding.
    • Communication: Email Sending Class (supporting SMTP, sendmail, and Mail with attachments/HTML) and XML-RPC Library.
    • Media & Files: Image Manipulation Library (supporting GD, ImageMagick, and NetPBM) and FTP Class.
    • Web Utilities: Pagination, Localization, User Agent Class, and Search-engine Friendly URLs via Flexible URI Routing.
    • Performance & Debugging: Benchmarking, Full Page Caching, Error Logging, Application Profiling, and Unit Testing.
    • Extensibility: Support for Hooks, Class Extensions, and a large library of helper functions.
  2. What is CodeIgniter 3

    develop

    CodeIgniter is a PHP application development framework designed to accelerate web development by providing a rich set of libraries for common tasks, a simple interface, and a logical structure.

    Note on Versioning: This repository contains CodeIgniter 3, which is the legacy version of the framework. It is intended for use with PHP 5.6+ and is currently in maintenance mode, receiving primarily security updates. For the latest version, use CodeIgniter 4.

  3. Overview of the Session Library

    develop

    The Session class allows you to maintain a user's 'state' and track their activity throughout their browsing session. CodeIgniter provides several built-in storage drivers to handle session data, which can be configured based on your application's needs.

    Supported storage drivers include:

    • files: The default driver, which uses the local file system.
    • database: Stores session data in a database table.
    • redis: Uses a Redis server for high-performance storage.
    • memcached: Uses Memcached for distributed memory caching.

    You can also implement custom session drivers to use alternative storage mechanisms while still utilizing the core features of the Session class.

  4. What is CodeIgniter?

    develop
    CodeIgniter is an Application Development Framework for PHP designed to accelerate web development. It provides a rich set of libraries for common tasks through a simple interface and logical structure, allowing developers to focus on project logic rather than boilerplate code. It is characterized by a small footprint, high performance, and minimal configuration requirements.
  5. Overview of XML-RPC and XML-RPC Server Classes

    develop

    CodeIgniter provides two primary classes for XML-RPC communication:

    1. XML-RPC Client: Used to send requests to a remote server.
    2. XML-RPC Server: Used to set up your own server to receive and process incoming XML-RPC requests.

    XML-RPC is a protocol that allows two computers to communicate over the internet using XML. The client sends an XML-RPC request, and the server responds with an XML-RPC response after processing the request.

  6. Overview of CodeIgniter Form Validation

    develop

    CodeIgniter provides a comprehensive form validation and data prepping class designed to minimize the boilerplate code required for handling user input. The library automates the lifecycle of form submission, including:

    1. Data Verification: Checking for required fields and ensuring data meets specific criteria (type, length, character sets, uniqueness, etc.).
    2. Security & Sanitization: Cleaning data to prevent common vulnerabilities.
    3. Data Prepping: Formatting data (e.g., trimming, HTML encoding) and preparing it for database insertion.
    4. Error Handling: Managing the redisplay of forms with error messages and preserving user input when validation fails.
  7. What is a Model in CodeIgniter?

    develop

    Models are PHP classes designed to manage information in your database. They are used to implement a traditional MVC (Model-View-Controller) approach, housing functions for inserting, updating, and retrieving data. Models should extend the base CI_Model class.

    class Blog_model extends CI_Model {
    
    	public $title;
    	public $content;
    	public $date;
    
    	public function get_last_ten_entries()
    	{
    		$query = $this->db->get('entries', 10);
    		return $query->result();
    	}
    
    	public function insert_entry()
    	{
    		$this->title = $_POST['title'];
    		$this->content = $_POST['content'];
    		$this->date = time();
    
    		$this->db->insert('entries', $this);
    	}
    
    	public function update_entry()
    	{
    		$this->title = $_POST['title'];
    		$this->content = $_POST['content'];
    		$this->date = time();
    
    		$this->db->update('entries', $this, array('id' => $_POST['id']));
    	}
    }
  8. Hide methods from public access

    develop

    To prevent certain methods from being accessible via a URL request, declare them as private or protected.

    Additionally, prefixing a method name with an underscore (_) will also prevent it from being called via URL (this is a legacy compatibility feature).

    class Blog extends CI_Controller {
    
        // This cannot be accessed via example.com/index.php/blog/_utility/
        private function _utility()
        {
            // some code
        }
    }
  9. Format request parameters with specific data types

    develop

    When sending requests, parameters can be sent as a simple array of values (if they are all strings). However, if you need to use specific XML-RPC data types (like int, boolean, or struct), you must wrap each parameter in its own array where the second element is the type name.

    Example of mixed data types:

    $request = array(
        array('John', 'string'),
        array('Doe', 'string'),
        array(FALSE, 'boolean'),
        array(12345, 'int')
    );
    $this->xmlrpc->request($request);
  10. How the Output class works

    develop

    The Output class is a core component responsible for sending the finalized web page to the browser and managing page caching.

    It is initialized automatically by the system. Under normal circumstances, it works transparently: when you use the Loader class to load a view, the content is automatically passed to the Output class and sent to the browser at the end of the system execution. However, developers can manually intervene to set specific content types, headers, or status codes.