当前位置:网站首页>PHP的CI框架学习
PHP的CI框架学习
2022-07-27 05:12:00 【铁柱同学】
一、前言
完全没想到新公司会使用CI框架,虽然一直听说,但是大家平时还是用laravel,yii,tp多一些,第一次接触CI,值得记录一下。
网上关于CI的文档很多,也很全面,博主这里只是简单的记录下。后续有需要记录的还会持续补充,,并不是一篇对新手很友好的文章了。。
二、CI入门
手册地址:http://codeigniter.org.cn/user_guide/
1、查看ci框架的版本号
项目中全局搜索:CI_VERSION
define('CI_VERSION', '2.x');
2、 CI框架设置默认的控制器
1.进入application的config文件夹下,找到routes.php
2.看到设置:$route['default_controller'] = "test"; // 含义是默认访问test控制器的index方法
3、核心类库的调用方式(system/core/config.php)
(1)控制器中调用核心库
$aa = $this->config->base_url();
(2)控制器中调用逻辑文件
$this->load->biz('test/test1'); // test1.php就是逻辑文件名
4、系统类库的调用(system/libraries/config.php)
$this->load->library('class_name'); //调用单个文件
$this->load->library(array('email', 'table')); //调用多个文件
$this->class_name->error_array(); //调用结束之后,就可以直接使用系统类库中的方法
5、辅助函数类的调用 (system/helps/test.php)
$this->load->library('test');
$casUserInfo = $this->test->xxx(); // 调用完可直接使用
6、模型类的调用 (system/models/model_name.php)
$this->load->model('blog/model_name'); 引用位于子目录下模型
$this->model_name->method(); 加载之后,你就可以通过一个和你的类同名的对象访问模型中的方法。
7、渲染页面
$this->load->view($template, $data, TRUE);
8、其他调用(redis)
//需要在config文件夹新建redis.php文件,里面写上配置等
$this->load->redis('key的名字'); //redis
9、获取和设置config的值
echo $this->config->item('charset'); //获取config中配置的charset值
$this->config->set_item('charset', 'gbk') //重新设置config中charset的值
10、以上方法皆为在controller中的调用,如果不在controller中怎么办?
要你自定义的类库中访问CodeIgniter的原始资源,你必须使用 get_instance() 函数.这个函数返回一个CodeIgniter super object.
$CI = &get_instance();
$CI->load->config('test1'); //加载core下的配置文件,例如test1.php
$CI->load->model('xxx/test_db'); // 加载model下的文件
$CI->load->library('http'); //加载 library下的文件
$CI->load->redis('test'); // 调用redis
$CI->load->rabbitmq('test'); // 调用rabbitmq
$CI->load->view($template, $data, TRUE); // 渲染页面
11、ci的命令行调用
调用方式:php index.php 控制器 方法 参数
示例:
*/1 * * * * php 项目目录/index.php test test_1 0 > /dev/null 2>&1
解释:
(1)类似于其他框架的命令行模式,前面是php位置,后面是项目根目录的index,php
(2) 后面的是用空格隔开的,控制器文件名(application里面的),方法名,参数
(3)方法示例:
// 这个就是对应的方法,$index是参数
public function test_1($index = 0)
{}
12、优秀入门博文推荐
https://www.cnblogs.com/lovele-/p/9434328.html
https://blog.csdn.net/qq_21806621/article/details/70992328
https://www.cnblogs.com/xiaoxiaoqingyi/p/6654190.html
end
边栏推荐
- What are alpha and beta tests?
- Sealem Finance - a new decentralized financial platform based on Web3
- 选择正规的资质好的期货公司开户
- MySQL索引分析除了EXPLAIN还有什么方法
- Personal collection code cannot be used for business collection
- When opening futures accounts, you should discuss the policy in detail with the customer manager
- 存储过程试炼1--爱的初相识
- Minio8.x version setting policy bucket policy
- 2022/7/26 考试总结
- Dimitra 和 Ocean Protocol 解读农业数据背后的秘密
猜你喜欢
随机推荐
本地ORACLE报ORA-12514: TNS:监听程序当前无法识别请求服务
How does gamefi break the circle? Aquanee shows its style by real "p2e"
二十五家互联网大厂软件测试笔试题总结,遇到包过。
期货公司开户的具体事项
刷脸支付用户主要优势是智能化程度高
难道Redis真的变慢了吗?
How to realize master-slave synchronization in mysql5.7
How can seektiger go against the cold air in the market?
How MySQL and redis ensure data consistency
亚马逊测评自养号,如何进行系统性的学习?
选择正规的资质好的期货公司开户
一文读懂Elephant Swap的LaaS方案的优势之处
Choose a qualified futures company to open an account
You should negotiate the handling fee before opening a futures account
Choose futures companies with state-owned enterprise background to open accounts
刷脸支付更符合支付宝一直做生态的理念
Integration and extension of robot programming and interdisciplinary
如果面试官问你 JVM,额外回答“逃逸分析”技术会让你加分
个人收款码不得用于经营收款
The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market









