<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter Application Controller Class
* 應用程序控制器類
*
* This class object is the super class that every library in
* CodeIgniter will be assigned to.
*
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/general/controllers.html
*/
class CI_Controller {
private static $instance;
/**
* Constructor
*/
public function __construct()
{
// 通過self::$instance實現單例化,在第一次實例時,這個靜態變量實質就是引用了這個實例。
// 以後都可以通過&get_instance();來獲得這個單一實例。構成這樣的單例模式的
// 好處就是單例類不會重複佔用內存和系統資源而是讓應用程序的其他部分更好的使用這些資源。
self::$instance =& $this;
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
// 分配在引導文件(CodeIgniter.php)中被實例化的類對象給$this
// 這樣CI可以運行一個超級對象。其實意思就是
// 把目前程序已經加載的所有的組件都給這個超級控制器來掌管。
foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class);
}
// 給超級控制器加載Loader組件,這個組件是它的好助手,
// 很多時候你會經常用到$this->load->xxx()的形式加載某個東西,
// 這個load就是控制器被構造的時候就伴隨存在的。
$this->load =& load_class('Loader', 'core');
// 初始化Loader組件,詳細Loader.php
$this->load->initialize();
log_message('debug', "Controller Class Initialized");
}
public static function &get_instance()
{
return self::$instance;
}
}
// END Controller class
/* End of file Controller.php */
/* Location: ./system/core/Controller.php */
CI框架源碼閱讀---------Controller.php
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.