### Basic Pagination Setup in CodeIgniter
Source: https://codeigniter.com/userguide3/libraries/pagination.html
This example demonstrates how to load the pagination library, set essential configuration options, and create pagination links within a controller method. Ensure 'base_url', 'total_rows', and 'per_page' are correctly configured for your application.
```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();
```
--------------------------------
### Install Sphinx and PHP Domain Extension
Source: https://codeigniter.com/userguide3/documentation/index.html
Use easy_install to install Sphinx and the sphinxcontrib-phpdomain extension. Ensure Python is installed.
```bash
easy_install "sphinx==1.2.3"
easy_install "sphinxcontrib-phpdomain==0.1.3.post1"
```
--------------------------------
### Usage Example
Source: https://codeigniter.com/userguide3/libraries/migration.html
Example controller to run migrations.
```APIDOC
## Usage Example
Place the following code in **application/controllers/Migrate.php** to update the schema.
### Method
This is a conceptual example of a controller for running migrations.
### Code Example
```php
load->library('migration');
if ($this->migration->current() === FALSE)
{
show_error($this->migration->error_string());
}
}
}
```
```
--------------------------------
### Caching Driver - Example Usage
Source: https://codeigniter.com/userguide3/libraries/caching.html
Demonstrates how to load the cache driver, specify an adapter (e.g., APC), and set a fallback adapter (e.g., file). It also shows how to get and save cache items, including setting an expiration time.
```APIDOC
## Caching Driver - Example Usage
The following example will load the cache driver, specify APC as the driver to use, and fall back to file-based caching if APC is not available in the hosting environment.
```php
$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
if ( ! $foo = $this->cache->get('foo'))
{
echo 'Saving to the cache!
';
$foo = 'foobarbaz!';
// Save into the cache for 5 minutes
$this->cache->save('foo', $foo, 300);
}
echo $foo;
```
You can also prefix cache item names via the **key_prefix** setting, which is useful to avoid collisions when you’re running multiple applications on the same environment.
```php
$this->load->driver('cache',
array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => 'my_')
);
$this->cache->get('foo'); // Will get the cache entry named 'my_foo'
```
```
--------------------------------
### Database Configuration Example (Oracle)
Source: https://codeigniter.com/userguide3/database/configuration.html
An example configuration for an Oracle database connection. Note the use of 'oci8' as the dbdriver and the 'hostname' format.
```php
$db['default']['hostname'] = '//localhost/XE';
$db['default']['username'] = 'admin_user';
$db['default']['password'] = 'admin_password';
$db['default']['database'] = 'my_oracle_db';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['encrypt'] = FALSE;
$db['default']['compress'] = FALSE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
```
--------------------------------
### _output() Method Example
Source: https://codeigniter.com/userguide3/general/controllers.html
An example of the _output() method, which receives the finalized output data before it's sent to the browser. This allows for post-processing of the output.
```php
public function _output($output)
{
echo $output;
}
```
--------------------------------
### Database Configuration Example (PostgreSQL)
Source: https://codeigniter.com/userguide3/database/configuration.html
An example configuration for a PostgreSQL database connection. Note the 'dbdriver' is set to 'postgre' and the 'port' is specified.
```php
$db['default'] = array(
'hostname' => 'localhost',
'port' => '5432',
'username' => 'my_username',
'password' => 'my_password',
'database' => 'my_database',
'dbdriver' => 'postgre',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
```
--------------------------------
### PHP Method Documentation Example
Source: https://codeigniter.com/userguide3/documentation/index.html
This example demonstrates the ReST syntax for documenting a PHP class method, including parameters, return types, and usage examples. It requires the `php:class` and `php:method` directives.
```rst
.. php:class:: Some_class
.. php:method:: some_method ( $foo [, $bar [, $bat]])
This function will perform some action. The ``$bar`` array must contain
a something and something else, and along with ``$bat`` is an optional
parameter.
:param int $foo: the foo id to do something in
:param mixed $bar: A data array that must contain a something and something else
:param bool $bat: whether or not to do something
:returns: FALSE on failure, TRUE if successful
:rtype: bool
::
$this->load->library('some_class');
$bar = array(
'something' => 'Here is this parameter!',
'something_else' => 42
);
$bat = $this->some_class->should_do_something();
if ($this->some_class->some_method(4, $bar, $bat) === FALSE)
{
show_error('An Error Occurred Doing Some Method');
}
.. note:: Here is something that you should be aware of when using some_method().
For real.
See also :meth:`Some_class::should_do_something`
.. php:method:: should_do_something()
:returns: Whether or not something should be done
:rtype: bool
```
--------------------------------
### Method Documentation Example
Source: https://codeigniter.com/userguide3/documentation/index.html
Example of documenting a class method using Sphinx directives, including parameters, return types, and code examples.
```APIDOC
## Method Documentation
When documenting class methods for third party developers, Sphinx provides directives to assist and keep things simple. For example, consider the following ReST:
```rst
.. php:class:: Some_class
.. php:method:: some_method ( $foo [, $bar [, $bat]])
This function will perform some action. The ``$bar`` array must contain
a something and something else, and along with ``$bat`` is an optional
parameter.
:param int $foo: the foo id to do something in
:param mixed $bar: A data array that must contain a something and something else
:param bool $bat: whether or not to do something
:returns: FALSE on failure, TRUE if successful
:rtype: bool
::
$this->load->library('some_class');
$bar = array(
'something' => 'Here is this parameter!',
'something_else' => 42
);
$bat = $this->some_class->should_do_something();
if ($this->some_class->some_method(4, $bar, $bat) === FALSE)
{
show_error('An Error Occurred Doing Some Method');
}
.. note:: Here is something that you should be aware of when using some_method().
For real.
See also :meth:`Some_class::should_do_something`
.. php:method:: should_do_something()
:returns: Whether or not something should be done
:rtype: bool
```
It creates the following display:
_class_`Some_class`
`some_method`(_$foo_[, _$bar_[, _$bat_]])
This function will perform some action. The `$bar` array must contain a something and something else, and along with `$bat` is an optional parameter.
Parameters:|
* **$foo** (_int_) – the foo id to do something in
* **$bar** (_mixed_) – A data array that must contain a something and something else
* **$bat** (_bool_) – whether or not to do something
---|---
Returns:| FALSE on failure, TRUE if successful
Return type:| bool
```php
$this->load->library('some_class');
$bar = array(
'something' => 'Here is this parameter!',
'something_else' => 42
);
$bat = $this->some_class->should_do_something();
if ($this->some_class->some_method(4, $bar, $bat) === FALSE)
{
show_error('An Error Occurred Doing Some Method');
}
```
Note
Here is something that you should be aware of when using some_method(). For real.
See also `Some_class::should_do_something()`
`should_do_something`()
Returns:| Whether or not something should be done
---|---
Return type:| bool
```
--------------------------------
### Database Configuration Example (MySQLi)
Source: https://codeigniter.com/userguide3/database/configuration.html
An example of a typical configuration for a MySQLi database connection. Ensure 'dbdriver' is set to 'mysqli' and fill in your specific connection details.
```php
$db['default'] = array(
'hostname' => 'localhost',
'username' => 'my_username',
'password' => 'my_password',
'database' => 'my_database',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
```
--------------------------------
### Example URI for Blog Controller
Source: https://codeigniter.com/userguide3/general/controllers.html
This is an example URI that would trigger the 'index' method of the 'blog' controller by default.
```plaintext
example.com/index.php/blog/index/
```
--------------------------------
### Example Pagination Query String Link
Source: https://codeigniter.com/userguide3/libraries/pagination.html
Demonstrates a pagination link when using query strings.
```http
http://example.com/index.php?c=test&m=page&per_page=20
```
--------------------------------
### Database Configuration Example (CubeDB)
Source: https://codeigniter.com/userguide3/database/configuration.html
Configuration for connecting to a CubeDB database. The 'dbdriver' is set to 'cubrid'.
```php
$db['default']['hostname'] = 'localhost';
$db['default']['port'] = '33000';
$db['default']['username'] = 'admin_user';
$db['default']['password'] = 'admin_password';
$db['default']['database'] = 'my_database';
$db['default']['dbdriver'] = 'cubrid';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['encrypt'] = FALSE;
$db['default']['compress'] = FALSE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
```
--------------------------------
### Example URL with Suffix
Source: https://codeigniter.com/userguide3/general/urls.html
Demonstrates how a URL appears after adding a suffix, such as '.html', for type hinting.
```text
example.com/index.php/products/view/shoes.html
```
--------------------------------
### Database Configuration Example (SQLite3)
Source: https://codeigniter.com/userguide3/database/configuration.html
Configuration for connecting to an SQLite3 database. The 'dbdriver' is set to 'sqlite3'.
```php
$db['default']['database'] = APPPATH.'database/my_database.db';
$db['default']['dbdriver'] = 'sqlite3';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['encrypt'] = FALSE;
$db['default']['compress'] = FALSE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
```
--------------------------------
### Controller Example with Dynamic Data
Source: https://codeigniter.com/userguide3/general/views.html
A controller example that prepares an associative array with data to be passed to a view. This data will be accessible as variables within the view file.
```php
load->view('blogview', $data);
}
}
```
--------------------------------
### Create a Migration
Source: https://codeigniter.com/userguide3/libraries/migration.html
Example of creating a new migration file to add a 'blog' table to the database.
```APIDOC
## Create a Migration
Migrations are stored in the **application/migrations/** directory and named with a timestamp prefix (e.g., `_20121031100537_add_blog.php`).
### Method
This is a conceptual example of a migration class.
### Code Example
```php
dbforge->add_field(array(
'blog_id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'blog_title' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'blog_description' => array(
'type' => 'TEXT',
'null' => TRUE,
),
));
$this->dbforge->add_key('blog_id', TRUE);
$this->dbforge->create_table('blog');
}
public function down()
{
$this->dbforge->drop_table('blog');
}
}
```
### Configuration
Set the migration version in **application/config/migration.php**:
```php
$config['migration_version'] = 20121031100537;
```
```
--------------------------------
### Database Configuration Example (ODBC)
Source: https://codeigniter.com/userguide3/database/configuration.html
Configuration for connecting to a database using ODBC. The 'dbdriver' is set to 'odbc'.
```php
$db['default']['dsn'] = 'your_odbc_dsn';
$db['default']['username'] = 'admin_user';
$db['default']['password'] = 'admin_password';
$db['default']['database'] = 'my_database';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['encrypt'] = FALSE;
$db['default']['compress'] = FALSE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
```
--------------------------------
### Initialize Library with Parameters
Source: https://codeigniter.com/userguide3/general/creating_libraries.html
Load a library and pass an array of parameters to its constructor.
```php
$params = array('type' => 'large', 'color' => 'red');
$this->load->library('someclass', $params);
```
--------------------------------
### Correct Class Naming Convention
Source: https://codeigniter.com/userguide3/general/styleguide.html
Example of a correct class naming convention, starting with an uppercase letter and using underscores for word separation.
```php
class Super_class
```
--------------------------------
### Invalid Controller Class Name
Source: https://codeigniter.com/userguide3/general/controllers.html
Controller class names must start with an uppercase letter. This example shows an invalid class name.
```php
load->helper('download');
```
## Available Functions
### `force_download`
Generates server headers which force data to be downloaded to your desktop. Useful with file downloads.
#### Parameters
- **$filename** (string) - Required - The desired name for the downloaded file.
- **$data** (mixed) - Optional - The content of the file to be downloaded. If NULL and `$filename` is a readable file path, its content will be read.
- **$set_mime** (bool) - Optional - Whether to attempt to send the actual MIME type based on the filename extension.
#### Return Type
void
#### Request Example (Downloading Data)
```php
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);
```
#### Request Example (Downloading an Existing File)
```php
// Contents of photo.jpg will be automatically read
force_download('/path/to/photo.jpg', NULL);
```
#### Request Example (Downloading with MIME Type)
```php
$data = 'Some binary data';
$name = 'archive.zip';
force_download($name, $data, TRUE);
```
```
--------------------------------
### Incorrect Class Naming Conventions
Source: https://codeigniter.com/userguide3/general/styleguide.html
Examples of incorrect class naming conventions that do not start with an uppercase letter or use CamelCase instead of underscores for separation.
```php
class superclass
class SuperClass
```
--------------------------------
### Get Clickable Smileys Example
Source: https://codeigniter.com/userguide3/helpers/smiley_helper.html
Returns an array of smiley images wrapped in clickable links. Requires the URL to the smiley directory and a field ID or alias.
```php
$image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comment');
```
--------------------------------
### Application Package Directory Structure
Source: https://codeigniter.com/userguide3/libraries/loader.html
This example shows the typical directory structure for an application package named 'Foo Bar', which can contain configuration, helpers, language files, libraries, and models.
```text
/application/third_party/foo_bar
config/
helpers/
language/
libraries/
models/
```
--------------------------------
### Set Calendar Display Preferences
Source: https://codeigniter.com/userguide3/libraries/calendar.html
Customize the calendar's appearance by passing an array of preferences to the calendar library loading function. This example sets the start day, month type, and day type.
```php
$prefs = array(
'start_day' => 'saturday',
'month_type' => 'long',
'day_type' => 'short'
);
$this->load->library('calendar', $prefs);
echo $this->calendar->generate();
```
--------------------------------
### Database Configuration Example (SQLite)
Source: https://codeigniter.com/userguide3/database/configuration.html
Configuration for an SQLite database connection. The 'database' parameter should be the full path to the database file.
```php
$db['default']['dbdriver'] = 'sqlite';
$db['default']['database'] = APPPATH.'database/my_database.db';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['encrypt'] = FALSE;
$db['default']['compress'] = FALSE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
```
--------------------------------
### Database Configuration Example (SQL Server Native Client)
Source: https://codeigniter.com/userguide3/database/configuration.html
Configuration for connecting to SQL Server using the native client. The 'dbdriver' is set to 'sqlsrv'.
```php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'admin_user';
$db['default']['password'] = 'admin_password';
$db['default']['database'] = 'my_database';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['encrypt'] = FALSE;
$db['default']['compress'] = FALSE;
$db['default']['stricton'] = FALSE;
$db['default']['failover'] = array();
$db['default']['save_queries'] = TRUE;
```
--------------------------------
### Retrieve GET or POST Data
Source: https://codeigniter.com/userguide3/libraries/input.html
Searches both GET and POST streams for the specified parameter, prioritizing GET. Optionally apply XSS filtering.
```php
$this->input->get_post(‘some_data’, TRUE);
```
--------------------------------
### Retrieve All GET Data
Source: https://codeigniter.com/userguide3/libraries/input.html
Call the get() method without parameters to retrieve all GET items. Use the second parameter to enable XSS filtering.
```php
$this->input->get(NULL, TRUE); // returns all GET items with XSS filter
```
```php
$this->input->get(NULL, FALSE); // returns all GET items without XSS filtering
```
--------------------------------
### Initializing the Utility Class
Source: https://codeigniter.com/userguide3/database/utilities.html
Demonstrates how to load the Database Utility Class. It can be loaded directly or with a specific database object.
```APIDOC
## Initializing the Utility Class
Important
In order to initialize the Utility class, your database driver must already be running, since the utilities class relies on it.
Load the Utility Class as follows:
```php
$this->load->dbutil();
```
You can also pass another database object to the DB Utility loader, in case the database you want to manage isn’t the default one:
```php
$this->myutil = $this->load->dbutil($this->other_db, TRUE);
```
In the above example, we’re passing a custom database object as the first parameter and then tell it to return the dbutil object, instead of assigning it directly to `$this->dbutil`.
Note
Both of the parameters can be used individually, just pass an empty value as the first one if you wish to skip it.
Once initialized you will access the methods using the `$this->dbutil` object:
```php
$this->dbutil->some_method();
```
```
--------------------------------
### Controller Example
Source: https://codeigniter.com/userguide3/helpers/smiley_helper.html
Example of how to use the Smileys helper and Table class within a CodeIgniter controller.
```APIDOC
## Controller Usage Example
### Description
This example demonstrates loading the smiley helper and table library, generating clickable smileys, and displaying them in a view.
### Method
GET
### Endpoint
/index.php/smileys/
### Request Body
None
### Response
HTML content displaying a form with a textarea and a table of clickable smileys.
### Request Example
```php
load->helper('smiley');
$this->load->library('table');
$image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comments');
$col_array = $this->table->make_columns($image_array, 8);
$data['smiley_table'] = $this->table->generate($col_array);
$this->load->view('smiley_view', $data);
}
}
```
```
--------------------------------
### FTP Class Usage Examples
Source: https://codeigniter.com/userguide3/libraries/ftp.html
Provides practical examples of using the CodeIgniter FTP Class for common operations.
```APIDOC
## Usage Examples
In this example a connection is opened to the FTP server, and a local file is read and uploaded in ASCII mode. The file permissions are set to 755.
```php
$this->load->library('ftp');
$config['hostname'] = 'ftp.example.com';
$config['username'] = 'your-username';
$config['password'] = 'your-password';
$config['debug'] = TRUE;
$this->ftp->connect($config);
$this->ftp->upload('/local/path/to/myfile.html', '/public_html/myfile.html', 'ascii', 0775);
$this->ftp->close();
```
In this example a list of files is retrieved from the server.
```php
$this->load->library('ftp');
$config['hostname'] = 'ftp.example.com';
$config['username'] = 'your-username';
$config['password'] = 'your-password';
$config['debug'] = TRUE;
$this->ftp->connect($config);
$list = $this->ftp->list_files('/public_html/');
print_r($list);
$this->ftp->close();
```
In this example a local directory is mirrored on the server.
```php
$this->load->library('ftp');
$config['hostname'] = 'ftp.example.com';
$config['username'] = 'your-username';
$config['password'] = 'your-password';
$config['debug'] = TRUE;
$this->ftp->connect($config);
$this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/');
$this->ftp->close();
```
```
--------------------------------
### CodeIgniter Tutorial
Source: https://codeigniter.com/userguide3/database/db_driver_reference.html
A step-by-step tutorial to help you build a simple application with CodeIgniter, covering static pages, a news section, and creating news items.
```APIDOC
## CodeIgniter Tutorial
### Description
Follow this tutorial to learn how to build a basic web application using CodeIgniter. It covers:
- Creating static pages
- Developing a news section
- Implementing functionality to create news items
- Conclusion and next steps
```
--------------------------------
### View Example
Source: https://codeigniter.com/userguide3/helpers/smiley_helper.html
Example of a CodeIgniter view file that utilizes the smiley_js function and displays the generated smiley table.
```APIDOC
## View Usage Example
### Description
This view file includes the necessary JavaScript for the smileys and displays the smiley table generated by the controller.
### Request Body
None
### Response
HTML content for the smiley view page.
### Request Example
```php
Click to insert a smiley!
``` ``` -------------------------------- ### Example CAPTCHA Image Tag Source: https://codeigniter.com/userguide3/helpers/captcha_helper.html This is an example of the HTML image tag that the create_captcha function generates for displaying the CAPTCHA. ```html
```
--------------------------------
### Load Library with Configuration Options
Source: https://codeigniter.com/userguide3/libraries/loader.html
Pass configuration settings as an array to the second parameter of the `library()` method to customize library behavior.
```php
$config = array (
'mailtype' => 'html',
'charset' => 'utf-8',
'priority' => '1'
);
$this->load->library('email', $config);
```
--------------------------------
### Retrieve Specific GET Data
Source: https://codeigniter.com/userguide3/libraries/input.html
This method is identical to post(), but fetches GET data. Optionally apply XSS filtering.
```php
$this->input->get('some_data', TRUE);
```
--------------------------------
### News Controller Setup
Source: https://codeigniter.com/userguide3/tutorial/news_section.html
Defines the News controller, loading the news model and URL helper. Used for managing news display logic.
```php
load->model('news_model');
$this->load->helper('url_helper');
}
public function index()
{
$data['news'] = $this->news_model->get_news();
}
public function view($slug = NULL)
{
$data['news_item'] = $this->news_model->get_news($slug);
}
}
```
--------------------------------
### Example Controller with Constructor
Source: https://codeigniter.com/userguide3/general/controllers.html
This example shows a typical CodeIgniter controller class with a constructor that calls the parent constructor and includes custom logic.
```php
input->method(TRUE); // Outputs: POST
```
```php
echo $this->input->method(FALSE); // Outputs: post
```
```php
echo $this->input->method(); // Outputs: post
```
--------------------------------
### Initialize Redis Driver
Source: https://codeigniter.com/userguide3/libraries/caching.html
Load the Redis driver and save data. Requires Redis server and phpredis PHP extension.
```php
$this->load->driver('cache');
$this->cache->redis->save('foo', 'bar', 10);
```
--------------------------------
### Retrieve POST or GET Data
Source: https://codeigniter.com/userguide3/libraries/input.html
Searches both POST and GET streams for the specified parameter, prioritizing POST. Optionally apply XSS filtering.
```php
$this->input->post_get('some_data', TRUE);
```
--------------------------------
### Accessing GET Data
Source: https://codeigniter.com/userguide3/libraries/input.html
Retrieve GET data using this method. It safely checks for the existence of the item and returns NULL if it's not set.
```php
$this->input->get('something');
```
--------------------------------
### Load a Library
Source: https://codeigniter.com/userguide3/general/creating_libraries.html
Initialize a custom library named 'someclass' from a controller.
```php
$this->load->library('someclass');
```
--------------------------------
### Creating a Database
Source: https://codeigniter.com/userguide3/database/forge.html
Details how to create a new database using the `create_database()` method.
```APIDOC
## POST /dbforge/create_database
### Description
Creates a new database.
### Method
POST
### Endpoint
/dbforge/create_database
### Parameters
#### Path Parameters
- **db_name** (string) - Required - The name of the database to create.
### Request Body
```json
{
"db_name": "new_database_name"
}
```
### Response
#### Success Response (200)
- **status** (boolean) - Indicates if the operation was successful.
#### Response Example
```json
{
"status": true
}
```
```
--------------------------------
### Query Builder - Get Data
Source: https://codeigniter.com/userguide3/database/examples.html
Use the get() function to retrieve all results from a specified table. Iterate over the results using the result() method.
```php
$query = $this->db->get('table_name');
foreach ($query->result() as $row)
{
echo $row->title;
}
```
--------------------------------
### Get URI Segments as Array - CodeIgniter
Source: https://codeigniter.com/userguide3/libraries/uri.html
Use `segment_array()` to get all URI segments as an array. This allows for easy iteration and access to individual segments.
```php
$segs = $this->uri->segment_array();
foreach ($segs as $segment)
{
echo $segment;
echo '{body}
{/blog_entries} ``` -------------------------------- ### Blogger API User Info Processing Example Source: https://codeigniter.com/userguide3/libraries/xmlrpc.html Example of a controller method processing a getUserInfo request for the Blogger API. It validates credentials and returns user data or an error. ```php class My_blog extends CI_Controller { public function getUserInfo($request) { $username = 'smitty'; $password = 'secretsmittypass'; $this->load->library('xmlrpc'); $parameters = $request->output_parameters(); if ($parameters[1] != $username && $parameters[2] != $password) { return $this->xmlrpc->send_error_message('100', 'Invalid Access'); } $response = array( array( 'nickname' => array('Smitty', 'string'), 'userid' => array('99', 'string'), 'url' => array('http://yoursite.com', 'string'), 'email' => array('jsmith@yoursite.com', 'string'), 'lastname' => array('Smith', 'string'), 'firstname' => array('John', 'string') ), 'struct' ); return $this->xmlrpc->send_response($response); } } ``` -------------------------------- ### Create Database with Forge Source: https://codeigniter.com/userguide3/database/forge.html Use the `create_database` method to create a new database. Returns TRUE on success, FALSE on failure. ```php if ($this->dbforge->create_database('my_db')) { echo 'Database created!'; } ``` -------------------------------- ### Trackback Ping URL Example Source: https://codeigniter.com/userguide3/libraries/trackback.html This is an example of a Ping URL format that external sites would use to send trackbacks to your application. The URL must include the entry ID. ```http http://example.com/index.php/trackback/receive/entry_id ``` -------------------------------- ### Example Pagination with Query String Reuse Source: https://codeigniter.com/userguide3/libraries/pagination.html Shows a pagination link that includes both URI segments and existing query string arguments. ```http http://example.com/index.php/test/page/20?query=search%term ``` -------------------------------- ### Specify Table for FROM Clause Source: https://codeigniter.com/userguide3/database/query_builder.html Use $this->db->from() to explicitly define the table for the FROM clause in your SQL query. This can be used in conjunction with $this->db->get() when the table name is not passed as a parameter to get(). ```php $this->db->select('title, content, date'); $this->db->from('mytable'); $query = $this->db->get(); // Produces: SELECT title, content, date FROM mytable ``` -------------------------------- ### Load Form Validation Library Source: https://codeigniter.com/userguide3/general/libraries.html Example of initializing the Form Validation Library. Ensure the library is available in the system/libraries directory. ```php $this->load->library('form_validation'); ``` -------------------------------- ### Load View with Return Option Source: https://codeigniter.com/userguide3/libraries/loader.html Use this method to load a view file. Set the third parameter to TRUE to return the view content as a string instead of sending it directly to the browser. ```php $string = $this->load->view('myfile', '', TRUE); ``` -------------------------------- ### GET /db/get_where Source: https://codeigniter.com/userguide3/database/query_builder.html Retrieves data from a table with a WHERE clause. ```APIDOC ## GET /db/get_where ### Description Identical to `$this->db->get()` except that it permits you to add a “where” clause in the second parameter, instead of using the `db->where()` function. ### Method GET ### Endpoint /db/get_where ### Parameters #### Query Parameters - **table** (string) - Required - The name of the table to select from. - **where_clause** (object) - Required - An object representing the WHERE clause conditions. - **limit** (int) - Optional - The number of records to retrieve. - **offset** (int) - Optional - The number of records to skip. ### Request Example ```json { "table": "mytable", "where_clause": {"id": 123}, "limit": 10, "offset": 20 } ``` ### Response #### Success Response (200) - **query_result** (object) - An object containing the results of the query. #### Response Example ```json { "query_result": [ { "id": 123, "title": "Example Title" } ] } ``` ``` -------------------------------- ### Configure Multiple Applications with One CodeIgniter Installation Source: https://codeigniter.com/userguide3/general/managing_apps.html To manage multiple applications with a single CodeIgniter installation, structure your directories with each application in its own subdirectory (e.g., 'applications/foo', 'applications/bar'). Then, set the `$application_folder` variable in the main index.php to point to the desired application's directory. ```php $application_folder = 'applications/foo'; ``` -------------------------------- ### Initialize XML-RPC Server Class Source: https://codeigniter.com/userguide3/libraries/xmlrpc.html Load both the XML-RPC and XML-RPC Server libraries. The server object will be available as $this->xmlrpcs. ```php $this->load->library('xmlrpc'); $this->load->library('xmlrpcs'); ``` -------------------------------- ### Get File Info Source: https://codeigniter.com/userguide3/helpers/file_helper.html Retrieves specified information about a file. ```APIDOC ## get_file_info ### Description Given a file and path, returns specified information attributes for a file. ### Method `get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))` ### Parameters #### Path Parameters - **$file** (string) - Required - File path - **$returned_values** (array) - Optional - What type of info to return (default: array('name', 'server_path', 'size', 'date')) - Valid options: name, size, date, readable, writeable, executable, fileperms ### Response #### Success Response - Returns: An array containing info on the specified file (array) #### Failure Response - Returns: FALSE on failure ### Request Example ```php // Get default info $file_info = get_file_info('some_file.txt'); // Get specific info $specific_info = get_file_info('another_file.log', array('name', 'size')); ``` ``` -------------------------------- ### Creating a Custom XML-RPC Client and Server Source: https://codeigniter.com/userguide3/libraries/xmlrpc.html This section provides examples for creating both a custom XML-RPC client and a server. The client prepares and sends a request, while the server registers a method and processes the request. ```php // The Client $this->xmlrpc->method('examples.getStateName'); $this->xmlrpc->parameter('80'); $this->xmlrpc->send(); // The Server $this->load->library('xmlrpc'); $this->xmlrpc->register_method('my.method', 'My_controller'); $this->xmlrpc->server_response(); ``` -------------------------------- ### Connect to FTP Server Source: https://codeigniter.com/userguide3/libraries/ftp.html Establishes a connection to the FTP server using provided configuration. Preferences can be set manually or stored in a config file. ```php $this->load->library('ftp'); $config['hostname'] = 'ftp.example.com'; $config['username'] = 'your-username'; $config['password'] = 'your-password'; $config['port'] = 21; $config['passive'] = FALSE; $config['debug'] = TRUE; $this->ftp->connect($config); ``` -------------------------------- ### Get Filenames Source: https://codeigniter.com/userguide3/helpers/file_helper.html Retrieves an array of filenames from a specified directory. ```APIDOC ## get_filenames ### Description Takes a server path as input and returns an array containing the names of all files contained within it. ### Method `get_filenames($source_dir, $include_path = FALSE)` ### Parameters #### Path Parameters - **$source_dir** (string) - Required - Directory path - **$include_path** (bool) - Optional - Whether to include the path as part of the filenames (default: FALSE) ### Response #### Success Response - Returns: An array of file names (array) ### Request Example ```php $controllers = get_filenames(APPPATH.'controllers/'); ``` ``` -------------------------------- ### Loading Multiple Language Files Source: https://codeigniter.com/userguide3/libraries/language.html Demonstrates loading multiple language files simultaneously by passing an array of filenames. ```php $this->lang->load(array('filename1', 'filename2')); ``` -------------------------------- ### Get Package Paths Source: https://codeigniter.com/userguide3/libraries/loader.html Returns an array of all currently available package paths. ```APIDOC ## GET /ci/loader/get_package_paths ### Description Retrieves all currently available package paths. ### Method GET ### Endpoint /ci/loader/get_package_paths ### Parameters #### Query Parameters - **include_base** (bool) - Optional - Whether to include BASEPATH. Defaults to TRUE. ### Response #### Success Response (200) - **paths** (array) - An array of package paths. ### Response Example ```json { "paths": [ "/path/to/package1", "/path/to/package2" ] } ``` ``` -------------------------------- ### Products Controller with Method Parameters Source: https://codeigniter.com/userguide3/general/controllers.html Demonstrates a controller method that accepts URI segments as parameters. The segments 'sandals' and 'id' are passed from the URI. ```php