当前位置:网站首页>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
边栏推荐
- Move protocol launched a beta version, and you can "0" participate in p2e
- 亚马逊测评自养号,如何进行系统性的学习?
- What happens to the new arrow function in ES6
- The difference between for... Of and for... In JS
- PHP 实现与MySQL的数据交互
- When opening futures accounts, you should discuss the policy in detail with the customer manager
- 难道Redis真的变慢了吗?
- MySQL索引分析除了EXPLAIN还有什么方法
- How to perform implicit conversion in JS
- What is the difference between foreach and map methods in JS
猜你喜欢

What are the conditions and procedures for opening crude oil futures accounts?

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output

记一次PG主从搭建及数据同步性能测试流程

jenkins构建镜像自动化部署

Aquanee will land in gate and bitmart in the near future, which is a good opportunity for low-level layout

Dimitra 和 Ocean Protocol 解读农业数据背后的秘密

Deploy redis with docker for high availability master-slave replication

How does gamefi break the circle? Aquanee shows its style by real "p2e"
基于PG-Oracle和MySQL的三库通用sql代码开发

DeFi 2.0的LaaS协议Elephant,或许是你熊市下为数不多的获利手段
随机推荐
How JS determines whether an object belongs to a class
How can I get the lowest handling charge for opening a futures account?
Move protocol launched a beta version, and you can "0" participate in p2e
When opening futures accounts, you should discuss the policy in detail with the customer manager
期货公司开户的具体事项
The business logic of face brushing changed significantly, and merchants vied for war smoke to rise again
NFT新范式,OKALEIDO创新NFT聚合交易生态
记一次PG主从搭建及数据同步性能测试流程
刷脸支付更符合支付宝一直做生态的理念
Do you really know session and cookies?
Sealem Finance - a new decentralized financial platform based on Web3
Graph-node部署及测试
选择国企背景的期货公司开户
未来刷脸支付是能够占据市场很多的份额
MySQL查询操作索引优化实践
Mysql5.7版本如何实现主从同步
Several ways of element positioning in page layout
如果面试官问你 JVM,额外回答“逃逸分析”技术会让你加分
NFT市场格局仍未变化,Okaleido能否掀起新一轮波澜?
MySQL如何执行查询语句