CodeIgniter框架解析
转载于:https://www.cnblogs.com/xiaoxiaoqingyi/p/6901654.html
转载仅为以后自己学习。
业余花了点时间看看CodeIgniter框架(简称CI),CI目前的稳定版本是 3.X,4.0版本已经出来了,但还在测试中,所以我分析的还是 3.x 版本。

- index.php 文件作为前端控制器,初始化运行 CodeIgniter 所需的基本资源;
- Router 检查 HTTP 请求,以确定如何处理该请求;
- 如果存在缓存文件,将直接输出到浏览器,不用走下面正常的系统流程;
- 在加载应用程序控制器之前,对 HTTP 请求以及任何用户提交的数据进行安全检查;
- 控制器加载模型、核心类库、辅助函数以及其他所有处理请求所需的资源;
- 最后一步,渲染视图并发送至浏览器,如果开启了缓存,视图被会先缓存起来用于 后续的请求。

主要有三个目录
1、application目录:用于开发者编写相应的配置以及逻辑处理,开发者只需在这个目录下添加自己需要的开发文件。
2、system目录:框架的系统库,里面包括核心库,类库,辅助类库,数据库等,这些文件,开发者最好不要擅自修改,它是整个框架的龙脉。
3、user_guide:用户手册。


{
● benchmark: "Benchmark",
● hooks: "Hooks",
● config: "Config",
● log: "Log",
● utf8: "Utf8",
● uri: "URI",
● router: "Router",
● output: "Output",
● security: "Security",
● input: "Input",
● lang: "Lang",
● loader: "Loader"
}

每个类库的注释在上图已有解释。
- pre_system 在系统执行的早期调用,这个时候只有 基准测试类 和 钩子类 被加载了, 还没有执行到路由或其他的流程。
- pre_controller 在你的控制器调用之前执行,所有的基础类都已加载,路由和安全检查也已经完成。
- post_controller_constructor 在你的控制器实例化之后立即执行,控制器的任何方法都还尚未调用。
- post_controller 在你的控制器完全运行结束时执行。
- post_system 在最终的页面发送到浏览器之后、在系统的最后期被调用。

/**
* Helper Loader
*
* @param string|string[] $helpers Helper name(s)
* @return object
*/
public function helper($helpers = array())
{
is_array($helpers) OR $helpers = array($helpers);
foreach ($helpers as &$helper)
{
$filename = basename($helper);
$filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename));
$filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper';
$helper = $filepath.$filename; if (isset($this->_ci_helpers[$helper]))
{
continue;
} // Is this a helper extension request?
$ext_helper = config_item('subclass_prefix').$filename;
$ext_loaded = FALSE;
foreach ($this->_ci_helper_paths as $path)
{
if (file_exists($path.'helpers/'.$ext_helper.'.php'))
{
include_once($path.'helpers/'.$ext_helper.'.php');
$ext_loaded = TRUE;
}
} // If we have loaded extensions - check if the base one is here
if ($ext_loaded === TRUE)
{
$base_helper = BASEPATH.'helpers/'.$helper.'.php';
if ( ! file_exists($base_helper))
{
show_error('Unable to load the requested file: helpers/'.$helper.'.php');
} include_once($base_helper);
$this->_ci_helpers[$helper] = TRUE;
log_message('info', 'Helper loaded: '.$helper);
continue;
} // No extensions found ... try loading regular helpers and/or overrides
foreach ($this->_ci_helper_paths as $path)
{
if (file_exists($path.'helpers/'.$helper.'.php'))
{
include_once($path.'helpers/'.$helper.'.php'); $this->_ci_helpers[$helper] = TRUE;
log_message('info', 'Helper loaded: '.$helper);
break;
}
} // unable to load the helper
if ( ! isset($this->_ci_helpers[$helper]))
{
show_error('Unable to load the requested file: helpers/'.$helper.'.php');
}
} return $this;
}

- 数组辅助函数
- 验证码辅助函数
- Cookie 辅助函数
- 日期辅助函数
- 目录辅助函数
- 下载辅助函数
- 邮件辅助函数
- 文件辅助函数
- 表单辅助函数
- HTML 辅助函数
- Inflector 辅助函数
- 语言辅助函数
- 数字辅助函数
- 路径辅助函数
- 安全辅助函数
- 表情辅助函数
- 字符串辅助函数
- 文本辅助函数
- 排版辅助函数
- URL 辅助函数
- XML 辅助函数
- 基准测试类
- 缓存驱动器
- 日历类
- 购物车类
- 配置类
- Email 类
- 加密类
- 加密类(新版)
- 文件上传类
- 表单验证类
- FTP 类
- 图像处理类
- 输入类
- Javascript 类
- 语言类
- 加载器类
- 迁移类
- 输出类
- 分页类
- 模板解析类
- 安全类
- Session 类
- HTML 表格类
- 引用通告类
- 排版类
- 单元测试类
- URI 类
- 用户代理类
- XML-RPC 与 XML-RPC 服务器类
- Zip 编码类
数据库

$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

提供了简单的查询缓存:
| Key | Description | Default |
| benchmarks | 在各个计时点花费的时间以及总时间 TRUE | |
| config | CodeIgniter 配置变量 TRUE | |
| controller_info | 被请求的控制器类和调用的方法 TRUE | |
| get | 请求中的所有 GET 数据 TRUE | |
| http_headers | 本次请求的 HTTP 头部 TRUE | |
| memory_usage | 本次请求消耗的内存(单位字节) TRUE | |
| post | 请求中的所有 POST 数据 TRUE | |
| queries | 列出所有执行的数据库查询,以及执行时间 TRUE | |
| uri_string | 本次请求的 URI TRUE | |
| session_data | 当前会话中存储的数据 TRUE | |
| query_toggle_count | 指定显示多少个数据库查询,剩下的则默认折叠起来 25 |
CodeIgniter框架解析的更多相关文章
- ***PHP中error_reporting()用法详解(含codeigniter框架中屏蔽错误提示的解决方案)
php中我们对错误的处理会常用到error_reporting函数了,大家可以看到最多的是error_reporting(E_ALL ^ E_NOTICE)了,这个到底什么意思呢,下面我来来看看. e ...
- CodeIgniter框架学习要点
以下内容从兄弟连的CI教学视频中摘抄: http://codeigniter.org.cn/tutorials/ ------------------------------------------- ...
- [转载]iOS 10 UserNotifications 框架解析
活久见的重构 - iOS 10 UserNotifications 框架解析 TL;DR iOS 10 中以前杂乱的和通知相关的 API 都被统一了,现在开发者可以使用独立的 UserNotifica ...
- 学习CodeIgniter框架之旅(一)自定义模板目录
在常用的框架本身都已经做好了分层和目录结构,但这在很多时候不满足项目的需求甚至在某些情况下变得不合理,因此很多时候需要自定义目录结构,在此就看看如果在CodeIgniter框架中自定义模板目录: 在C ...
- ABP使用及框架解析系列 - [Unit of Work part.1-概念及使用]
前言 ABP ABP是“ASP.NET Boilerplate Project”的简称. ABP的官方网站:http://www.aspnetboilerplate.com ABP在Github上的开 ...
- ABP使用及框架解析系列 - [Unit of Work part.2-框架实现]
前言 ABP ABP是“ASP.NET Boilerplate Project”的简称. ABP的官方网站:http://www.aspnetboilerplate.com ABP在Github上的开 ...
- CodeIgniter框架入门教程——第三课 URL及ajax
本文转载自:http://www.softeng.cn/?p=74 这节课讲一下CI框架的路由规则,以及如何在CI框架下实现ajax功能. 首先,先介绍CI框架的路由规则,因为CI框架是在PHP的基础 ...
- CI(CodeIgniter)框架入门教程——第二课 初始MVC
本文转载自:http://www.softeng.cn/?p=53 今天的主要内容是,使用CodeIgniter框架完整的MVC内容来做一个简单的计算器,通过这个计算器,让大家能够体会到我在第一节课中 ...
- iOS 10 UserNotifications 框架解析
摘自:https://onevcat.com/2016/08/notification/ iOS 10 中以前杂乱的和通知相关的 API 都被统一了,现在开发者可以使用独立的 UserNotifica ...
随机推荐
- 利用python把成绩用雷达图表示出来
第一步:知道自己的成绩. 第二步:插入代码. import numpy as np import matplotlib.pyplot as plt import matplotlib matplotl ...
- Java集合类学习笔记2
二,具体的集合 集合类型 描述 ArrayList 一种可以动态增长和缩减的索引序列 LinkedList 一种可以在任何位置进行高效地插入和删除操作的有序序列 ArrayDeque 一种用循环数组实 ...
- 在linux上安装python, jupyter, 虚拟环境(virtualenv)以及 虚拟环境管理之virtualenvwraper
一, 安装python31.下载python3源码 wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz2.解压缩源码包,去 ...
- 安卓抓包https
https://blog.csdn.net/yichengace/article/details/80167878
- es6中promise实现ajax的例子
function getData(url){ var pro = new Promise(function(resolve,reject){ var xhr = null; try{ xhr = ne ...
- 0x11栈之Editor
参考链接:https://blog.csdn.net/SSLGZ_yyc/article/details/81700623 对顶栈的思想: 建立两个栈,栈A存储从序列开头到当前光标的位置的一段序列,栈 ...
- Hello2 source analysis
在example目录下的web\servlet\hello2\src\main\java\javaeetutorial\hello2路径里可以找到hello2的GreetingServlet.java ...
- Windows环境下利用anaconda3安装python版本的Xgboost
网上有各种不同安装Xgboost的教程,但是有些教程对于一个新手来说,照着做安装成功是很困难的.本人也是新手,第一次安装Xgboost的时候,照着某个教程做,结果总是安装不上,甚至想到要放弃.后来经一 ...
- 彻底清除 Windows 服务
如果服务已经停止, 或从注册表中删除, 但是在任务管理器中仍能看到服务躺在列表里面. 只需要找到服务的PID, 然后运行命令: taskkill /PID 服务的PID /f 即可.
- 【做题】CSA72G - MST and Rectangles——Borůvka&线段树
原文链接 https://www.cnblogs.com/cly-none/p/CSA72G.html 题意:有一个\(n \times n\)的矩阵\(A\),\(m\)次操作,每次在\(A\)上三 ...