Creating Drivers

Driver Directory and File Structure Sample driver directory and file structure layout: /application/libraries/Driver_nameDriver_name.php driversDriver_name_subclass_1.php Driver_name_subclass_2.php Driver_name_subclass_3.php Note In order to maintain compatibility on case-sensitive file systems, the Driver_name directory must be named in the format returned by ucfirst(). Note The Driver library’s architecture is such that the subclasses don’t extend and therefore don’t inherit properties

Creating Core System Classes

Every time CodeIgniter runs there are several base classes that are initialized automatically as part of the core framework. It is possible, however, to swap any of the core system classes with your own versions or even extend the core versions. Most users will never have any need to do this, but the option to replace or extend them does exist for those who would like to significantly alter the CodeIgniter core. Note Messing with a core system class has a lot of implications, so make sure you

create_captcha()

create_captcha([$data = ''[, $img_path = ''[, $img_url = ''[, $font_path = '']]]]) Parameters: $data (array) – Array of data for the CAPTCHA $img_path (string) – Path to create the image in $img_url (string) – URL to the CAPTCHA image folder $font_path (string) – Server path to font Returns: array(‘word’ => $word, ‘time’ => $now, ‘image’ => $img) Return type: array Takes an array of information to generate the CAPTCHA as input and creates the image to your specifications

Create news items

You now know how you can read data from a database using CodeIgniter, but you haven’t written any information to the database yet. In this section you’ll expand your news controller and model created earlier to include this functionality. Create a form To input data into the database you need to create a form where you can input the information to be stored. This means you’ll be needing a form with two fields, one for the title and one for the text. You’ll derive the slug from our title in the

convert_accented_characters()

convert_accented_characters($str) Parameters: $str (string) – Input string Returns: A string with accented characters converted Return type: string Transliterates high ASCII characters to low ASCII equivalents. Useful when non-English characters need to be used where only standard ASCII characters are safely used, for instance, in URLs. Example: $string = convert_accented_characters($string); Note This function uses a companion config file application/config/foreign_chars.php to d

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

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

config_item()

config_item($key) Parameters: $key (string) – Config item key Returns: Configuration key value or NULL if not found Return type: mixed The Config Library is the preferred way of accessing configuration information, however config_item() can be used to retrieve single keys. See Config Library documentation for more information.

Conclusion

This tutorial did not cover all of the things you might expect of a full-fledged content management system, but it introduced you to the more important topics of routing, writing controllers, and models. We hope this tutorial gave you an insight into some of CodeIgniter’s basic design patterns, which you can expand upon. Now that you’ve completed this tutorial, we recommend you check out the rest of the documentation. CodeIgniter is often praised because of its comprehensive documentation. Use

CodeIgniter URLs

By default, URLs in CodeIgniter are designed to be search-engine and human friendly. Rather than using the standard “query string” approach to URLs that is synonymous with dynamic systems, CodeIgniter uses a segment-based approach: example.com/news/article/my_article Note Query string URLs can be optionally enabled, as described below. URI Segments The segments in the URL, in following with the Model-View-Controller approach, usually represent: example.com/class/function/ID The first segmen