Common Functions in CodeIgniter
0 2719
- Codeigniter provides some functions that are used globally defined.
- We can use these functions anywhere throughout the application.
- Unlike libraries and helper functions, these functions do not require initialization before use.
Related Topics:
Codeigniter Interview Questions
Cookie Management in Codeigniter
Models in Codeigniter
CodeIgniter Common Functions:
Some common functions are listed below: 1 is_php(): This function is used to get the information about PHP versions. This function returns boolean TRUE if the installed version of PHP is equal to or greater than the supplied version number and returns FALSE otherwise. Syntax:is_php($version);Parameter description:
- $version (string) − Version number The return type of this function void and this function returns TRUE if the running PHP version is at least the one specified or FALSE if not. 2 is_really_writable(): This function determines if a file is actually writable or not. Syntax:
is_really_writable();Parameter description:
config_item($key);Parameter description:
set_status_header($code[, $text = '']);Parameter description:
remove_invisible_characters($str[, $url_encoded = TRUE])Parameter description:
html_escape($var);Parameter description:
get_mimes();The return type of this function array and this function returns an associative array of file types. 8 is_https(): This function returns TRUE if a secure (HTTPS) connection is used and FALSE in any other case (including non-HTTP requests). Syntax:
is_https();The return type of this function bool and this function returns TRUE if currently using HTTP-over-SSL, FALSE if not. 9 is_cli(): This function is used to determine the application is run through the command line or not. Syntax:
is_cli();The return type of this function bool and this function returns TRUE if currently running under CLI, FALSE otherwise. 10 function_usable(): This function is used to check a function exists and is usable or not. Syntax:
function_usable($function_name);Parameter description:
Example: Step 1 Open the application/controllers directory and create a new controller file Common_controller.php.
<?phpStep 2 Open the given URL into the browser to see the result.
class Common_controller extends CI_Controller {
public 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_cli():".var_dump(is_cli())."<br>";
var_dump(function_usable('test'))."<br>";
echo "get_mimes():".print_r(get_mimes())."<br>";
}
public function test() {
echo "Test function";
}
}
?>
http://localhost/ci/index.php/Common_controller

Share:




Comments
Waiting for your comments