CodeIgniter 框架的简单分析

来源:互联网 发布:simon口语 知乎 编辑:程序博客网 时间:2024/04/29 18:33
作者: archerchu
来源: http://www.eb163.com/club/thread-1429-1-1.html


CodeIgniter 关键的核心文件是那个Loader.php,他主要定义了加载数据库配置、View、文件和类的方法。

CI的基础类是CI_Base,这里又分为PHP4、PHP5两个不同的方式,不过原理都是一样的,单例模式方法。
PHP复制代码
class CI_Base {
private static $instance;
public function CI_Base()
{
  self::$instance =& $this;
}
public static function &get_instance()
{
  return self::$instance;
}
}
function &get_instance()
{
return CI_Base::get_instance();
}
复制代码


控制器是Controller继承CI_Base的
PHP复制代码
class Controller extends CI_Base
复制代码


值得注意的是function _ci_scaffolding(),它里面主要定义了一些Scaffolding的method,你可以扩展Scaffolding的method
PHP复制代码
$method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view','delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3);
复制代码


Scaffolding被称为脚手架,很难理解,其实就是定义了一些method方法,处理页面view的,在 Scaffolding里面你能找到刚才的一些默认定义。也就是说,CI可以通过Scaffolding来处理Controller、View、 Model的关系。如果需要我们可以扩展Scaffolding,让他能完成除了'add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'更多的东西。

Model没什么说的,就是一个实体类Entity,主要对这个Entity的属性、方法进行定义的。

总结一下,CI这个框架其实就是类的继承和模版的加载把Controller、View、Model有机的结合起来,各自发挥各自的特长。
原创粉丝点击