在使用CodeIgniter库函数和帮助器函数之前,需要先对其进行初始化,但是有些通用函数不需要初始化。
这些常用函数及其说明如下。
链接:https://www.learnfk.comhttps://www.learnfk.com/codeigniter/codeigniter-common-functions.html
来源:LearnFk无涯教程网
set_status_header($code,[,$text='']):设置自定义头部信息
is_really_write($file) : 判断路径是否可写,如果是,则返回True,否则False
config_item($key) : 获取key信息,如果不存在,则返回NULL
is_php($version) : 判断是否是指定的版本号。
remove_invisible_characters($str[,$url_enoded=TRUE]): 过滤字符串
html_escape($var) : HTML转义字符串
get_mimes() : 返回文件类型MIMES数组
is_https(): 如果当前使用基于HTTP的SSL,则为TRUE,否则为FALSE
is_cli() : 如果当前正在CLI下运行,则为TRUE,否则为FALSE
function_usable($function_name) :如果函数存在并且可用,则返回TRUE,否则返回FALSE。
在这里,无涯教程仅创建了一个将使用上述函数的控制器。复制以下给定的代码并将其保存在 application/controller/CommonFun_Controller.php 中。
<?php class CommonFun_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"; } } ?>
更改application/config/routes.php中的 routes.php 文件,为上述控制器添加路由,并在文件末尾添加以下行。
$route['commonfunctions']='CommonFun_Controller';
在浏览器的地址栏中键入以下URL以执行示例。
http://yoursite.com/index.php/commonfunctions
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)