標籤:
/control/admin/frame.php的流程結構類似於這樣:/control/admin/frame.php -->調用父類adminbase的建構函式,(/model/adminbase的執行個體)-->adminbase類的建構函式,調用父類base類的建構函式(/model/base.php),真正幹活的是base類的建構函式,所以,我們直接看base類的建構函式都實現了什麼。
//建構函式
function __construct() {
$this->base();
}
//base函數
function base() {
//調用內建函式,
$this->init_var();
//初始化資料庫和串連資料庫資訊
$this->init_db();
//引入//data/cache下面的檔案,並載入全部的應用資訊
$this->init_cache();
//初始化所用的應用ID
$this->init_app();
//初始化使用者資訊
$this->init_user();
$this->init_template();
//發送通知函數
$this->init_note();
$this->init_mail();
//$this->cron();
}
可以看到,base乾的話有:
- 初始化成員變數onlineip,lang
- 建立資料庫連接
- 將需要的資料表中的資訊寫到/data/cache對應的檔案,可以說,你在/data/cache/目錄下面看到的內容都是對應的表格中的資料,這樣以來就可以提高代碼效率。不需要重複讀寫資料庫
- 從上一步中的/data/cache/apps.php檔案中讀取對應的appid內容
- 讀取瀏覽器的cookie,使用/data/cache/apps.php檔案中讀取出對應appid的密鑰,解密cookie,然後解出userid,username
- 設定預設主題
- 使用fsock()向各個應用發生通知
- 發生email
這個是base的建構函式的功能,adminbase類調用完父類的建構函式,就會執行頁面的載入,我們可以看代碼:
function adminbase() {
//調用父類的建構函式
parent::__construct();
$this->cookie_status = isset($_COOKIE[‘sid‘]) ? 1 : 0;
$sid = $this->cookie_status ? getgpc(‘sid‘, ‘C‘) : rawurlencode(getgpc(‘sid‘, ‘R‘));
$this->view->sid = $sid;
$this->view->assign(‘sid‘, $this->view->sid);
$this->view->assign(‘iframe‘, getgpc(‘iframe‘));
$a = getgpc(‘a‘);
if(getgpc(‘m‘) !=‘user‘ && $a != ‘login‘ && $a != ‘logout‘) {
$this->check_priv();
}
}
執行了父類的建構函式,就會執行自己的check_priv(),check_prive()的函數代碼如下 :
$username = $this->sid_decode($this->view->sid);
if(empty($username)) {
header(‘Location: ‘.UC_API.‘/admin.php?m=user&a=login&iframe=‘.getgpc(‘iframe‘, ‘G‘).($this->cookie_status ? ‘‘ : ‘&sid=‘.$this->view->sid));
exit;
這是部分代碼,所以,第一次進ucenter出現 的登陸介面,就是這個函數實現。我們看地址欄的url:http://ucenter.xadieu.com/admin.php?m=user&a=login&iframe=&sid=
是不是一樣的。所以,我們看到了登陸介面。下一篇,我們會對base.php的建構函式做一個詳細介紹。
Ucenter源碼解析--frame.php