DISCUZ 之论坛首页加载过程,FORUM相关

可能有理解不透彻的地方,欢迎回帖拍砖,会多加改进

1、加载class_core.php可查看全局数据初始化的另外一个笔记

2、功能模块中哦跟你的mod对应了source/forum中指定的文件。
缓存模块根据当前所处的功能模块,加载必需的缓存内容,默认的缓存内容一般会在操作完指定模块之后存放在用二进制的形式序列化后存放在数据库表中
//BBS相关的功能模块   
$modarray = array('ajax','announcement','attachment','forumdisplay',   
    'group','image','index','medal','misc','modcp','notice','post','redirect',   
    'relatekw','relatethread','rss','topicadmin','trade','viewthread','tag','collection','guide'
);   
  
//缓存相关的数据模块   
$modcachelist = array(   
    'index'     => array('announcements', 'onlinelist', 'forumlinks',   
            'heats', 'historyposts', 'onlinerecord', 'userstats', 'diytemplatenameforum'),   
    'forumdisplay'  => array('smilies', 'announcements_forum', 'globalstick', 'forums',   
            'onlinelist', 'forumstick', 'threadtable_info', 'threadtableids', 'stamps', 'diytemplatenameforum'),   
    'viewthread'    => array('smilies', 'smileytypes', 'forums', 'usergroups',   
            'stamps', 'bbcodes', 'smilies', 'custominfo', 'groupicon', 'stamps',   
            'threadtableids', 'threadtable_info', 'posttable_info', 'diytemplatenameforum'),   
    'redirect'  => array('threadtableids', 'threadtable_info', 'posttable_info'),   
    'post'      => array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes',   
            'domainwhitelist', 'albumcategory'),   
    'space'     => array('fields_required', 'fields_optional', 'custominfo'),   
    'group'     => array('grouptype', 'diytemplatenamegroup'),   
);

//对于不在modarray中的值,视为非法内容,直接替换成index。   
//C::app()->var['mod']的值在加载class_core.php时初始化函数_init_input()中已经赋值,起始就是URL中的一个参数值   
$mod = !in_array(C::app()->var['mod'], $modarray) ? 'index' : C::app()->var['mod'];

其中C是core的一个子类
C::app()->cachelist = $cachelist;   
C::app()->init();

    如果说class_core.php是执行初始化的工作,或者说声明必要的内容,那么这里的C::app()->init()就是把基本上需要的内容都获取到,例如数据库连接,后台设置的内容,用户信息,session信息等等。具体往下看。
public function init() {   
        if(!$this->initated) {   
            $this->_init_db();   
            $this->_init_setting();   
            $this->_init_user();   
            $this->_init_session();   
            $this->_init_mobile();   
            $this->_init_cron();   
            $this->_init_misc();   
        }   
        $this->initated = true;   
}

    一样,从各个函数中的名称可以稍微理解每个都会进行些什么相关的内容,这一点在加载class_core.php时就遇到了,core类的构造函数的操作方式就跟这个很是类似。

3、该函数的主要任务就是连接数据库,重点所连接的时候涉及到不同数据库版本对字符集的设置问题
private function _init_db() {   
        if($this->init_db) {   
            $driver = 'db_driver_mysql';   
            if(count(getglobal('config/db/slave'))) {   
                $driver = 'db_driver_mysql_slave';   
            }   
            DB::init($driver, $this->config['db']);   
        }   
}

     DB类在加载class_core.php的最后继承了class DB extends discuz_database {}类discuz_database,稍微查看下该文件就可以看出,对于数据库相关的操作如获取数据库配置信息,连接数据库,查询、删除、更新数据库表等都重新封装过。
    init_db变量在声明该类的时候就初始化默认为true,而db_driver_mysql中基本上封装了需要用到的数据库操作,而discuz_database就可以当作是一个代理,而正真完成操作的则为在更为底层的db_driver_mysql.
    至于db_driver_mysql_slave暂时还没有怎么留意到,后续补充

public static function init($driver, $config) {   
        self::$driver = $driver;   
        self::$db = new $driver;   
        self::$db->set_config($config);   
        self::$db->connect();   
}

    如上所说,这里的$driver=db_driver_mysql,其中set_config 就是为了得到数据的配置信息,HOST、名、用户、密码等包括数据库前缀

4、
private function _init_setting() {   
        if($this->init_setting) {   
            if(empty($this->var['setting'])) {   
                $this->cachelist[] = 'setting';   
            }   
  
     
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值