- CodeIgniter - Security
- CodeIgniter - Internationalization
- CodeIgniter - Adding JS and CSS
- CodeIgniter - Benchmarking
- CodeIgniter - Application Profiling
- CodeIgniter - Page Redirection
- CodeIgniter - Page Caching
- CodeIgniter - Common Functions
- CodeIgniter - Cookie Management
- CodeIgniter - Tempdata
- CodeIgniter - Flashdata
- CodeIgniter - Session Management
- CodeIgniter - Form Validation
- CodeIgniter - Sending Email
- CodeIgniter - File Uploading
- CodeIgniter - Error Handling
- CodeIgniter - Libraries
- CodeIgniter - Working with Database
- CodeIgniter - Configuration
- CodeIgniter - Basic Concepts
- CodeIgniter - MVC Framework
- CodeIgniter - Application Architecture
- CodeIgniter - Installing CodeIgniter
- CodeIgniter - Overview
- CodeIgniter - Home
CodeIgniter Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
CodeIgniter - Common Functions
CodeIgniter pbrary functions and helper functions need to be initiapzed before they are used but there are some common functions, which do not need to be initiapzed.
These common functions and their descriptions are given below.
Syntax | is_php($version) |
---|---|
Parameters |
$version (string) − Version number |
Return | TRUE if the running PHP version is at least the one specified or FALSE if not |
Return Type | void |
Description | Determines if the PHP version being used is greater than the suppped version number. |
Syntax | is_really_writable($file) |
---|---|
Parameters |
$file (string) − File path |
Return | TRUE if the path is writable, FALSE if not |
Return Type | bool |
Description | checks to see if file is writable or not. |
Syntax | config_item($key) |
---|---|
Parameters |
$key (string) − Config item key |
Return | Configuration key value or NULL if not found |
Return Type | mixed |
Description | This function is used to get the configuration item |
Syntax | set_status_header($code[, $text = ]) |
---|---|
Parameters |
$code (int) − HTTP Response status code $text (string) − A custom message to set with the status code |
Return | |
Return Type | void |
Description | This function permits you to manually set a server status header. |
Syntax | remove_invisible_characters($str[, $url_encoded = TRUE]) |
---|---|
Parameters |
$str (string) − Input string $url_encoded (bool) − Whether to remove URLencoded characters as well |
Return | Sanitized string |
Return Type | string |
Description | This function prevents inserting NULL characters between ASCII characters |
Syntax | html_escape($var) |
---|---|
Parameters |
$var (mixed) − Variable to escape (string or array) |
Return | HTML escaped string(s) |
Return Type | mixed |
Description | This function acts as a native PHP htmlspecialchars() function. |
Syntax | get_mimes() |
---|---|
Return | An associative array of file types |
Return Type | array |
Description | This function returns a reference to the MIMEs array from apppcation/config/mimes.php. |
Syntax | is_https() |
---|---|
Return | TRUE if currently using HTTP-over-SSL, FALSE if not |
Return Type | bool |
Description | Returns TRUE if a secure (HTTPS) connection is used and FALSE in any other case (including non-HTTP requests). |
Syntax | is_cp() |
---|---|
Return | TRUE if currently running under CLI, FALSE otherwise |
Return Type | bool |
Description | Returns TRUE if the apppcation is run through the command pne and FALSE if not. |
Syntax | function_usable($function_name) |
---|---|
Parameters |
$function_name (string) − Function name |
Return Type | bool |
Description | Returns TRUE if a function exists and is usable, FALSE otherwise. |
Given below is an example, which demonstrates all of the above functions.
Example
Here we have created only one controller in which we will use the above functions. Copy the below given code and save it at apppcation/controller/CommonFun_Controller.php.
<?php class CommonFun_Controller extends CI_Controller { pubpc function index() { set_status_header(200); echo is_php( 5.3 )."<br>"; var_dump(is_really_writable( ./Form.php )); echo config_item( language )."<br>"; echo remove_invisible_characters( This is a test , UTF8 )."<br>"; $str = < This > is a " test & string ; echo html_escape($str)."<br>"; echo "is_https():".var_dump(is_https())."<br>"; echo "is_cp():".var_dump(is_cp())."<br>"; var_dump(function_usable( test ))."<br>"; echo "get_mimes():".print_r(get_mimes())."<br>"; } pubpc function test() { echo "Test function"; } } ?>
Change the routes.php file at apppcation/config/routes.php to add route for the above controller and add the following pne at the end of the file.
$route[ commonfunctions ] = CommonFun_Controller ;
Type the following URL in the address bar of your browser to execute the example.
http://yoursite.com/index.php/commonfunctionsAdvertisements