### Example: Load Captcha Plugin
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/plugins.html
An example of loading the 'captcha' plugin, which corresponds to the 'captcha_pi.php' file. This illustrates the naming convention for the plugin loading function.
```PHP
$this->load->plugin('captcha');
```
--------------------------------
### Toggle Table of Contents Navigation
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/overview/getting_started.html
This snippet demonstrates how to toggle the table of contents navigation using JavaScript. It's typically used in documentation sites to provide a better user experience.
```html
```
--------------------------------
### CodeIgniter User Guide Typos and Examples
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Corrects various typos and inaccurate examples found within the user guide documentation.
```Markdown
This section details corrections made to the user guide, including fixing typos and updating examples to ensure accuracy.
```
--------------------------------
### CodeIgniter User Model Example
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/models.html
An example of a CodeIgniter model class named 'User_model', illustrating the naming conventions for class names and corresponding file names.
```PHP
class User_model extends Model {
function User_model()
{
parent::Model();
}
}
```
--------------------------------
### Run Transactions Manually (CodeIgniter)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/transactions.html
This example demonstrates manual transaction management in CodeIgniter. It uses trans_begin() to start a transaction and then trans_rollback() or trans_commit() based on the transaction status.
```php
$this->db->trans_begin();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
}
else {
$this->db->trans_commit();
}
```
--------------------------------
### Correct Calendar Example for Navigation
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Updates an example in the Calendar library to accurately demonstrate showing next/previous month links.
```PHP
/*
* Fixed an example in the Calendar library for Showing Next/Previous Month Links.
*/
```
--------------------------------
### Example View File with Pseudo-Variables
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/parser.html
A sample HTML view file demonstrating the use of pseudo-variables and variable pairs for dynamic content insertion via the Template Parser Class.
```html
{blog_title}
{blog_heading}
{blog_entries}
{title}
{body}
{/blog_entries}
```
--------------------------------
### CodeIgniter Controller Loading Model and View
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/models.html
An example of a CodeIgniter controller that loads a model, retrieves data, and then passes that data to a view.
```PHP
class Blog_controller extends Controller {
function blog()
{
$this->load->model('Blog');
$data['query'] = $this->Blog->get_last_ten_entries();
$this->load->view('blog', $data);
}
}
```
--------------------------------
### Correct XML RPC Example
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Fixes an example provided for XML RPC to ensure its accuracy and clarity.
```PHP
/*
* Fixed an example for XML RPC.
*/
```
--------------------------------
### Trackback Ping URL Example
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/trackback.html
Illustrates the format of a Ping URL for receiving trackbacks, which must include the entry ID.
```http
http://example.com/index.php/trackback/receive/entry_id
```
--------------------------------
### Correct Email Example in Documentation
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Fixes an example in the email library documentation that incorrectly showed comma-separated emails.
```PHP
/*
* Fixed an example of comma-separated emails in the email library documentation.
*/
```
--------------------------------
### CodeIgniter Blog Model Example
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/models.html
An example of a CodeIgniter model class for managing blog data, including functions for inserting, updating, and retrieving entries. It utilizes the Active Record database functions.
```PHP
class Blogmodel extends Model {
var $title = '';
var $content = '';
var $date = '';
function Blogmodel()
{
// Call the Model constructor
parent::Model();
}
function get_last_ten_entries()
{
$query = $this->db->get('entries', 10);
return $query->result();
}
function insert_entry()
{
$this->title = $_POST['title']; // please read the below note
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('entries', $this);
}
function update_entry()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('entries', $this, array('id' => $_POST['id']));
}
}
```
--------------------------------
### Force Download Text Data with CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/download_helper.html
This example shows how to use the force_download() function from the Download Helper to download a string of text as a file. It specifies the desired filename and the data content.
```php
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);
```
--------------------------------
### Connect with Custom Database Configuration - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/connecting.html
This example shows how to manually connect to a database by providing custom configuration values as an array in CodeIgniter. It includes parameters like hostname, username, password, database name, and driver.
```php
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$this->load->database($config);
```
--------------------------------
### Add example for Associative Arrays in XMLRPC (CodeIgniter 1.6.3)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Includes an example demonstrating how to use associative arrays within XMLRPC request parameters on the userguide page.
```php
/*
* Added "Using Associative Arrays In a Request Parameter" example to the [XMLRPC userguide page](libraries/xmlrpc.html).
*/
```
--------------------------------
### PHP CodeIgniter Template Example
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/overview/at_a_glance.html
This snippet demonstrates how CodeIgniter handles template parsing using native PHP, contrasting it with a hypothetical template engine's pseudo-code. It highlights CodeIgniter's focus on performance by avoiding mandatory template engines.
```PHP
```
--------------------------------
### Get Site and System URLs in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/config.html
Provides examples of using helper functions within the CodeIgniter Config class to retrieve the site URL and the system URL, based on the application's configuration.
```php
$this->config->site_url();
$this->config->system_url();
```
--------------------------------
### CodeIgniter: Custom Core Library Initialization
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Allows passing custom initialization parameters to core libraries in CodeIgniter when using $this->load->library(), providing more control over library setup.
```PHP
Added the ability to pass your own initialization parameters to your [custom core libraries](creating_libraries.html) when using $this->load->library()
```
--------------------------------
### CodeIgniter Controller with Validation Rules
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/form_validation.html
A complete CodeIgniter controller example demonstrating the initialization of the Form Validation library and the setting of multiple validation rules for form fields.
```php
load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required'); $this->form_validation->set_rules('email', 'Email', 'required'); if ($this->form_validation->run() == FALSE) { $this->load->view('myform'); } else { $this->load->view('formsuccess'); } } }
```
--------------------------------
### Connect with DSN and Query String Overrides - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/connecting.html
This example shows how to connect to a database using a DSN string in CodeIgniter while overriding default configuration values using query string parameters. This allows for flexible connection settings.
```php
$dsn = 'dbdriver://username:password@hostname/database?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=/path/to/cache';
$this->load->database($dsn);
```
--------------------------------
### Generate HTML Table with Discrete Row Parameters
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/table.html
Provides an example of building an HTML table by setting headings and adding rows individually using discrete parameters.
```php
$this->load->library('table');
$this->table->set_heading('Name', 'Color', 'Size');
$this->table->add_row('Fred', 'Blue', 'Small');
$this->table->add_row('Mary', 'Red', 'Large');
$this->table->add_row('John', 'Green', 'Medium');
echo $this->table->generate();
```
--------------------------------
### Send Trackback Data in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/trackback.html
Provides an example of sending trackback data, including ping URL, entry URL, title, excerpt, blog name, and charset. It also shows how to handle success or failure.
```php
$this->load->library('trackback');
$tb_data = array(
'ping_url' => 'http://example.com/trackback/456',
'url' => 'http://www.my-example.com/blog/entry/123',
'title' => 'The Title of My Entry',
'excerpt' => 'The entry content.',
'blog_name' => 'My Blog Name',
'charset' => 'utf-8'
);
if ( ! $this->trackback->send($tb_data)) {
echo $this->trackback->display_errors();
}
else {
echo 'Trackback was sent!';
}
```
--------------------------------
### Create a Basic CodeIgniter Controller
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/controllers.html
Demonstrates how to create a simple 'Hello World' controller in CodeIgniter. This involves defining a class that extends the base Controller and includes an index function.
```php
```
--------------------------------
### Configure CodeIgniter Database Settings (PHP)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/installation/index.html
This snippet shows how to configure database connection settings in CodeIgniter's `application/config/database.php` file. It includes parameters such as the database driver, hostname, username, password, and database name, essential for database interactions.
```PHP
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
```
--------------------------------
### CodeIgniter: Get Query Results as Arrays
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Retrieves query results as a pure array. This is useful when you prefer accessing data using array keys. The example demonstrates iterating through the results.
```php
$query = $this->db->query("YOUR QUERY");
foreach ($query->result_array() as $row) {
echo $row['title'];
echo $row['name'];
echo $row['body'];
}
```
--------------------------------
### Initialize Database Utility Class
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/utilities.html
Loads the Database Utility class, which is required before accessing its functions. The database driver must be running for initialization.
```PHP
$this->load->dbutil()
```
--------------------------------
### CodeIgniter Pagination Basic Setup
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/pagination.html
Demonstrates the fundamental steps to initialize and use the CodeIgniter Pagination library within a controller. It requires loading the library and setting essential configuration parameters like base URL, total rows, and items per page.
```php
$this->load->library('pagination');
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = '200';
$config['per_page'] = '20';
$this->pagination->initialize($config);
echo $this->pagination->create_links();
```
--------------------------------
### CodeIgniter: Get Single Row as Array
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Fetches a single result row as an array. Similar to `row()`, but returns an associative array. The example demonstrates accessing data using array keys.
```php
$query = $this->db->query("YOUR QUERY");
if ($query->num_rows() > 0) {
$row = $query->row_array();
echo $row['title'];
echo $row['name'];
echo $row['body'];
}
```
--------------------------------
### CodeIgniter Overview
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/overview/index.html
This section provides a high-level overview of the CodeIgniter framework, linking to detailed explanations of its features, architecture, and design principles.
```PHP
```
--------------------------------
### CodeIgniter: Get Query Results as Objects
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Retrieves query results as an array of objects. Useful for iterating through results using object properties. Includes an example of checking the number of rows before processing.
```php
$query = $this->db->query("YOUR QUERY");
foreach ($query->result() as $row) {
echo $row->title;
echo $row->name;
echo $row->body;
}
```
```php
$query = $this->db->query("YOUR QUERY");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
echo $row->title;
echo $row->name;
echo $row->body;
}
}
```
--------------------------------
### PHP Library Class with Constructor Parameters
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/creating_libraries.html
Demonstrates how to define a constructor for a CodeIgniter library class to accept initialization parameters. These parameters can be passed during the library loading process.
```php
```
--------------------------------
### CodeIgniter: Get Single Row as Object
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Fetches a single result row as an object. If multiple rows exist, it returns the first one. The example shows how to access object properties after retrieving the row.
```php
$query = $this->db->query("YOUR QUERY");
if ($query->num_rows() > 0) {
$row = $query->row();
echo $row->title;
echo $row->name;
echo $row->body;
}
```
--------------------------------
### Initialize Upload Library - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/file_uploading.html
This PHP code demonstrates how to initialize the CodeIgniter Upload library. It shows the standard method of loading the library with specific configuration settings passed during initialization. An alternative method using the `initialize()` function is also mentioned for cases where the class is auto-loaded.
```PHP
$this->load->library('upload');
```
```PHP
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);
```
--------------------------------
### Document get() in Input class (CodeIgniter 1.6.3)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Provides documentation for the existing get() method within the Input class.
```php
/*
* Documented get() in the [Input class](libraries/input.html).
*/
```
--------------------------------
### Load Download Helper in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/download_helper.html
This code snippet demonstrates how to load the Download Helper in CodeIgniter, which is necessary to use its functions.
```php
$this->load->helper('download');
```
--------------------------------
### Form Helper form_open() GET Method
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
The form_open() helper function has been updated to allow the use of the GET method for form submissions.
```PHP
echo form_open('controller/method', 'GET');
```
--------------------------------
### Import CSS
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Imports an external CSS file named 'userguide.css' to style the user guide content.
```CSS
@import url('userguide.css');
```
--------------------------------
### PHP Short Open Tags vs. Full Open Tags
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/styleguide.html
Recommends using full PHP opening tags (
```
--------------------------------
### Upgrade Notes Links
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/installation/upgrading.html
This section lists the available upgrade notes for transitioning between different versions of CodeIgniter. Each link points to a specific document detailing the changes and steps required for that particular version upgrade.
```text
* [Upgrading from 1.7.1 to 1.7.2](upgrade_172.html)
* [Upgrading from 1.7.0 to 1.7.1](upgrade_171.html)
* [Upgrading from 1.6.3 to 1.7.0](upgrade_170.html)
* [Upgrading from 1.6.2 to 1.6.3](upgrade_163.html)
* [Upgrading from 1.6.1 to 1.6.2](upgrade_162.html)
* [Upgrading from 1.6.0 to 1.6.1](upgrade_161.html)
* [Upgrading from 1.5.4 to 1.6.0](upgrade_160.html)
* [Upgrading from 1.5.3 to 1.5.4](upgrade_154.html)
* [Upgrading from 1.5.2 to 1.5.3](upgrade_153.html)
* [Upgrading from 1.5.0 or 1.5.1 to 1.5.2](upgrade_152.html)
* [Upgrading from 1.4.1 to 1.5.0](upgrade_150.html)
* [Upgrading from 1.4.0 to 1.4.1](upgrade_141.html)
* [Upgrading from 1.3.3 to 1.4.0](upgrade_140.html)
* [Upgrading from 1.3.2 to 1.3.3](upgrade_133.html)
* [Upgrading from 1.3.1 to 1.3.2](upgrade_132.html)
* [Upgrading from 1.3 to 1.3.1](upgrade_131.html)
* [Upgrading from 1.2 to 1.3](upgrade_130.html)
* [Upgrading from 1.1 to 1.2](upgrade_120.html)
* [Upgrading from Beta 1.0 to Beta 1.1](upgrade_b11.html)
```
--------------------------------
### Initialize CodeIgniter Library
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/libraries.html
Demonstrates how to load a CodeIgniter library within a controller using the $this->load->library() method. This is a fundamental step for utilizing the framework's built-in functionalities.
```php
$this->load->library('class name');
```
```php
$this->load->library('validation');
```
--------------------------------
### DBForge Database Creation and Dropping
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
This snippet demonstrates the functionality for creating and dropping databases using the DBForge tool. It highlights the methods moved into DBForge for managing database structures.
```PHP
create_database()
drop_database()
```
--------------------------------
### Get Database Version - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/helpers.html
Outputs the version number of the database currently in use.
```PHP
echo $this->db->version();
```
--------------------------------
### Load and Use Foo Library
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/doc_style/template.html
This snippet demonstrates how to load the 'foo' library in CodeIgniter and then call the 'bar' method with a 'bat' argument. It's a basic example of interacting with a custom library.
```PHP
$this->load->library('foo');
$this->foo->bar('bat');
```
--------------------------------
### Get Random Element from Array
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/array_helper.html
Illustrates the usage of the random_element() function to pick and return a random item from a given array.
```php
$quotes = array(
"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
"Don't stay in bed, unless you can make money in bed. - George Burns",
"We didn't lose the game; we just ran out of time. - Vince Lombardi",
"If everything seems under control, you're not going fast enough. - Mario Andretti",
"Reality is merely an illusion, albeit a very persistent one. - Albert Einstein",
"Chance favors the prepared mind - Louis Pasteur"
);
echo random_element($quotes);
```
--------------------------------
### Get Database Platform - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/helpers.html
Outputs the name of the database platform currently in use (e.g., MySQL, PostgreSQL).
```PHP
echo $this->db->platform();
```
--------------------------------
### Pass Dynamic Data to Controller for View
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/views.html
Example of setting dynamic data (title and heading) in a controller and passing it to the 'blogview' for display.
```PHP
load->view('blogview', $data); } }
```
--------------------------------
### Initialize XML-RPC Server Classes in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/xmlrpc.html
This snippet demonstrates loading both the XML-RPC and XML-RPC Server classes in CodeIgniter. Both libraries are required when setting up an XML-RPC server. The objects are then accessible as `$this->xmlrpc` and `$this->xmlrpcs`.
```php
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
```
--------------------------------
### PHP: Create XML-RPC Server with Method Mapping
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/xmlrpc.html
Loads the XML-RPC Server library and initializes it with configuration. The configuration maps incoming XML-RPC method names (e.g., 'new_post') to specific controller methods (e.g., 'My_blog.new_entry') for processing.
```PHP
$this->load->library('xmlrpc'); $this->load->library('xmlrpcs'); $config['functions']['new_post'] = array('function' => 'My_blog.new_entry'), $config['functions']['update_post'] = array('function' => 'My_blog.update_entry'); $config['object'] = $this; $this->xmlrpcs->initialize($config); $this->xmlrpcs->serve();
```
--------------------------------
### Create a Simple View File
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/views.html
This snippet shows how to create a basic HTML view file for CodeIgniter. The file is saved in the application/views/ directory.
```HTML
My Blog Welcome to my Blog!
```
--------------------------------
### Get Trackback Error Messages in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/trackback.html
Shows how to retrieve error messages from the Trackback library if a trackback sending operation fails.
```php
$this->trackback->display_errors();
```
--------------------------------
### CodeIgniter MVC Components Explained
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/overview/mvc.html
This documentation explains the three core components of the Model-View-Controller (MVC) pattern as used in CodeIgniter: Model, View, and Controller. It outlines their respective responsibilities in handling data, presentation, and request processing.
```text
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 a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of "page".
The **Controller** serves as an _intermediary_ between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.
```
--------------------------------
### CodeIgniter: Get Specific Row as Array
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Retrieves a specific row from the query result as an array by providing the row number as a parameter.
```php
$row = $query->row_array(5);
```
--------------------------------
### PHP Class and File Name Prefixes
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/styleguide.html
Provides guidance on prefixing class and file names with a unique identifier to prevent naming collisions with other scripts or add-ons. This is crucial for maintaining code integrity in shared environments.
```PHP
```
--------------------------------
### CodeIgniter: Get Specific Row as Object
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Retrieves a specific row from the query result as an object by providing the row number as a parameter.
```php
$row = $query->row(5);
```
--------------------------------
### Loading String Helper - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/string_helper.html
Demonstrates how to load the String Helper in CodeIgniter. This is typically done once at the beginning of a controller or library.
```php
$this->load->helper('string');
```
--------------------------------
### Get Last Query String - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/helpers.html
Returns the last SQL query string that was executed, not the result set. Useful for debugging.
```PHP
$str = $this->db->last_query();
```
--------------------------------
### CodeIgniter Private Function Example
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/controllers.html
Demonstrates how to make a function private by prefixing its name with an underscore. Private functions cannot be accessed via URL requests.
```PHP
function _utility() {
// some code
}
```
--------------------------------
### Import CSS Stylesheet
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/toc.html
This line imports an external CSS file named 'userguide.css' to style the web page. It's a standard way to apply consistent styling across a website.
```CSS
@import url('userguide.css');
```
--------------------------------
### Get Insert ID - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/helpers.html
Retrieves the ID number generated when performing database inserts. This function is part of the CodeIgniter Database Library.
```PHP
$this->db->insert_id()
```
--------------------------------
### Underscore Conversion - CodeIgniter Inflector
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/inflector_helper.html
Converts a string of words separated by spaces into a format with underscores using the `underscore()` function. Shows an example of its application.
```php
$word = "my dog spot";
echo underscore($word); // Returns "my_dog_spot"
```
--------------------------------
### PHP CodeIgniter Resource Access
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/creating_libraries.html
Shows how to access CodeIgniter's super object within a custom library to utilize framework resources like helpers, libraries, and configuration items. It uses the get_instance() function.
```php
$CI =& get_instance();
$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
```
--------------------------------
### Update CodeIgniter Constants File
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/installation/upgrade_162.html
This step involves copying the constants.php configuration file from the system application directory to the installation and modifying it as needed.
```PHP
Copy /system/application/config/constants.php to your installation, and modify if necessary.
```
--------------------------------
### PHP: Fix Superglobal Unset Vulnerability
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
A security vulnerability that allowed unsetting certain PHP superglobals by setting them via GET or POST data has been fixed.
```PHP
Fixed a bug where one could unset certain PHP superglobals by setting them via GET or POST data
```
--------------------------------
### Add get_post() to Input class (CodeIgniter 1.6.3)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Introduces the get_post() method to the Input class, providing a convenient way to retrieve both GET and POST data.
```php
/*
* Added get_post() to the [Input class](libraries/input.html).
*/
```
--------------------------------
### Load Database with Options (PHP)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/loader.html
Demonstrates loading the database class with optional parameters. Refer to the database section of the user guide for more detailed information on database configuration and usage.
```PHP
$this->load->database('options', true);
```
--------------------------------
### CodeIgniter: Get Number of Query Fields
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Returns the number of columns (fields) in the query result set. This function should be called on the query result object.
```php
$query = $this->db->query('SELECT * FROM my_table');
echo $query->num_fields();
```
--------------------------------
### Load CodeIgniter URL Helper
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/url_helper.html
Demonstrates how to load the URL Helper in CodeIgniter, which is necessary to use its associated functions.
```php
$this->load->helper('url');
```
--------------------------------
### Decode Data with CodeIgniter Encryption
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/encryption.html
Provides an example of how to decrypt a previously encrypted string using the CodeIgniter Encryption class. This is essential for retrieving the original data.
```php
$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';
$plaintext_string = $this->encrypt->decode($encrypted_string);
```
--------------------------------
### Load a Replaced or Custom Library in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/creating_libraries.html
Load a custom or replaced library in CodeIgniter using the standard `$this->load->library()` function, referencing the library by its name without any prefixes.
```php
$this->load->library('email');
```
--------------------------------
### Singular Word Conversion - CodeIgniter Inflector
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/inflector_helper.html
Converts a plural word to its singular form using the `singular()` function from the Inflector Helper. Shows an example of its usage.
```php
$word = "dogs";
echo singular($word); // Returns "dog"
```
--------------------------------
### Get Array Element with Default Value
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/array_helper.html
Shows how to use the element() function to safely retrieve an item from an array, providing a default value if the item does not exist or is empty.
```php
$array = array('color' => 'red', 'shape' => 'round', 'size' => '');
echo element('color', $array);
// returns "red"
echo element('size', $array, NULL);
// returns NULL
```
--------------------------------
### CodeIgniter: Get Number of Query Rows
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/results.html
Returns the total number of rows returned by a database query. This is useful for checking if a query produced any results before processing them.
```php
$query = $this->db->query('SELECT * FROM my_table');
echo $query->num_rows();
```
--------------------------------
### Configure CodeIgniter Base URL and Encryption Key (PHP)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/installation/index.html
This snippet demonstrates how to set the base URL and encryption key within the CodeIgniter configuration file (`application/config/config.php`). The base URL is crucial for the framework's operation, and the encryption key is used for data encryption and session security.
```PHP
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically will be your domain name, e.g.
|
| http://example.com/
|
*/
$config['base_url'] = '';
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encrypt class you must set an encryption key here.
|
|--------------------------------------------------------------------------
*/
$config['encryption_key'] = '';
```
--------------------------------
### CodeIgniter URL Helper: base_url(), index_page()
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
The URL Helper includes functions like `base_url()` and `index_page()` to assist in generating URLs for your application. `base_url()` returns your site's base URL, while `index_page()` returns the entry point of your application (e.g., index.php).
```PHP
base_url()
```
```PHP
index_page()
```
--------------------------------
### Humanize String Conversion - CodeIgniter Inflector
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/inflector_helper.html
Converts a string with underscores into a human-readable format with spaces and capitalized words using the `humanize()` function. Includes a practical example.
```php
$word = "my_dog_spot";
echo humanize($word); // Returns "My Dog Spot"
```
--------------------------------
### Camel Case Conversion - CodeIgniter Inflector
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/inflector_helper.html
Converts a string of words separated by spaces or underscores into camel case using the `camelize()` function. Provides an example input and output.
```php
$word = "my_dog_spot";
echo camelize($word); // Returns "myDogSpot"
```
--------------------------------
### Toggle Table of Contents
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/installation/downloads.html
This snippet demonstrates how to toggle the visibility of the table of contents using JavaScript. It's a common UI pattern for documentation sites.
```javascript
javascript:void(0);
```
--------------------------------
### Connect to Multiple Databases - CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/connecting.html
This CodeIgniter code demonstrates how to establish simultaneous connections to multiple databases. By setting the second parameter of `load->database()` to TRUE, the database object is returned, allowing separate management of each connection.
```php
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
```
--------------------------------
### Manage Transaction Errors (CodeIgniter)
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/database/transactions.html
This example illustrates how to manage potential errors during CodeIgniter database transactions. It checks the transaction status after completion and provides a placeholder for error handling, such as logging.
```php
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
// generate an error... or use the log_message() function to log your error
}
```
--------------------------------
### Initialize Trackback Class in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/trackback.html
Demonstrates how to load and access the Trackback library within a CodeIgniter controller.
```php
$this->load->library('trackback');
```
--------------------------------
### Marking Benchmark Points in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/benchmark.html
This snippet demonstrates how to mark specific points in your CodeIgniter application to measure execution time. You can define arbitrary names for your start and end points.
```php
$this->benchmark->mark('code_start'); // Some code happens here $this->benchmark->mark('code_end'); echo $this->benchmark->elapsed_time('code_start', 'code_end');
```
```php
$this->benchmark->mark('dog'); // Some code happens here $this->benchmark->mark('cat'); // More code happens here $this->benchmark->mark('bird'); echo $this->benchmark->elapsed_time('dog', 'cat'); echo $this->benchmark->elapsed_time('cat', 'bird'); echo $this->benchmark->elapsed_time('dog', 'bird');
```
--------------------------------
### CodeIgniter Fetch SERVER Data
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/input.html
Illustrates fetching SERVER data using the input->server() method.
```PHP
$this->input->server('some_data');
```
--------------------------------
### Retrieving Uploaded File Data in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/file_uploading.html
This snippet demonstrates how to use the `data()` method of the CodeIgniter Upload library to get an array containing all information about the successfully uploaded file.
```PHP
$this->load->library('upload');
if ($this->upload->do_upload()) {
$upload_data = $this->upload->data();
print_r($upload_data);
/*
Array
(
[file_name] => mypic.jpg
[file_type] => image/jpeg
[file_path] => /path/to/your/upload/
[full_path] => /path/to/your/upload/jpg.jpg
[raw_name] => mypic
[orig_name] => mypic.jpg
[client_name] => mypic.jpg
[file_ext] => .jpg
[file_size] => 22.2
[is_image] => 1
[image_width] => 800
[image_height] => 600
[image_type] => jpeg
[image_size_str]=> width="800" height="200"
)
*/
}
```
--------------------------------
### Load an Extended Library in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/creating_libraries.html
Load an extended library in CodeIgniter using the standard `$this->load->library()` function, referencing the library by its original name without the 'MY_' prefix.
```php
$this->load->library('email');
```
--------------------------------
### PHP Callback Validation Example
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/form_validation.html
Demonstrates how to set a custom validation rule using a callback function in CodeIgniter. The callback checks if the username is not 'test' and sets a custom error message if it is.
```PHP
load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('myform');
} else {
$this->load->view('formsuccess');
}
}
function username_check($str) {
if ($str == 'test') {
$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
} else {
return TRUE;
}
}
}
?>
```
--------------------------------
### Force Download Existing File with CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/download_helper.html
This snippet illustrates how to download an existing file from the server using the force_download() function. It reads the file's content into a string using file_get_contents() and then passes it along with the desired filename.
```php
$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
$name = 'myphoto.jpg';
force_download($name, $data);
```
--------------------------------
### PHP: Deprecate is_numeric() Usage
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
The use of is_numeric() has been deprecated in favor of a regular expression (preg_match("/[^0-9]/", $n)) due to compatibility issues with ctype_digit() and its unreliability in some installations.
```PHP
Deprecated the use if is_numeric() in various places since it allows periods. Due to compatibility problems with ctype_digit(), making it unreliable in some installations, the following regular expression was used instead: preg_match("/[^0-9]/", $n)
```
--------------------------------
### CodeIgniter Direct vs. Helper Data Fetching
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/libraries/input.html
Compares direct access to superglobal arrays (like $_POST) with CodeIgniter's helper functions, highlighting the safety and convenience of the latter.
```PHP
if ( ! isset($_POST['something'])) {
$something = FALSE;
} else {
$something = $_POST['something'];
}
```
```PHP
$something = $this->input->post('something');
```
--------------------------------
### CodeIgniter: Get Last Query
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/changelog.html
Introduces the $this->db->last_query() method in CodeIgniter, allowing developers to retrieve and inspect the last SQL query executed by the database driver. This is invaluable for debugging.
```PHP
Added [$this->db->last_query()](./database/queries.html), which allows you to view your last query that was run.
```
--------------------------------
### Database Table Naming Convention
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/styleguide.html
Defines the standard naming convention for database tables used by add-ons. Tables must be prefixed with 'exp_', followed by a unique developer prefix, and then a descriptive table name, adhering to MySQL's 64-character limit.
```SQL
-- INCORRECT: email_addresses // missing both prefixes
-- INCORRECT: pre_email_addresses // missing exp_ prefix
-- INCORRECT: exp_email_addresses // missing unique prefix
-- CORRECT: exp_pre_email_addresses
```
--------------------------------
### Map Directory Contents in CodeIgniter
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/helpers/directory_helper.html
Demonstrates how to use the `directory_map` function to get an array representation of a directory's contents. It includes options to map only the top level and to include hidden files.
```php
$map = directory_map('./mydirectory/');
```
```php
$map = directory_map('./mydirectory/', TRUE);
```
```php
$map = directory_map('./mydirectory/', FALSE, TRUE);
```
--------------------------------
### Load Multiple CodeIgniter Plugins
Source: https://github.com/allanfreitas/eci/blob/master/user_guide/general/plugins.html
Shows how to load multiple plugins at once by passing an array of plugin names to the load function. This is useful for loading several plugins simultaneously.
```PHP
$this->load->plugin( array('plugin1', 'plugin2', 'plugin3') );
```