zoukankan      html  css  js  c++  java
  • yii框架学习笔记2

    简介:这是yii框架学习笔记2的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

    class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339160' scrolling='no'>
    分析页面执行一次操作进行的处理流程:


    在capplication的__construct中执行
    $this->registerCoreComponents();//加载核心组件
    在这里实际上会首先 调用cwebapplication的registerCoreComponents()函数,在函数中会执行parent::registerCoreComponents();即执行capplication的registerCoreComponents(),

    注册核心组件,然后注册cwebapplication里面的核心组件。

    在这两个函数中都会调用cmodule的setComponents(); //2次
    下面还有1次

    $this->configure($config); //设置配置去除了bashPath的config数组成为当前类的属性
    这里注意会用到ccomponent.php的魔术方法__set($name,$value)
    在config文件里面的数组注册为类的属性的时候会调用这个魔术函数,因为类文件本身没有声明config中的key代表的属性,即不存在属性所以会调用__set

    public function __set($name,$value)
    {
    $setter='set'.$name;
    if(method_exists($this,$setter))
    return $this->$setter($value);

    如果存在set.$name这个方法,设置config数组成属性的时候,就要用到这个。

    比如在config中有component数组

    'components'=>array(
    'user'=>array(
    // enable cookie-based authentication
    'allowAutoLogin'=>true,
    ),
    /*
    'db'=>array(
    'connectionString' => 'sqlite:protected/data/blog.db',
    'tablePrefix' => 'tbl_',
    ),
    */
    // uncomment the following to use a MySQL database

    'db'=>array(
    'connectionString' => 'mysql:host=localhost;dbname=testdrive',
    'emulatePrepare' => true,
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
    'tablePrefix' => 'tbl_',
    ),

    'errorHandler'=>array(
    // use 'site/error' action to display errors
    'errorAction'=>'site/error',
    ),
    /*
    'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
    'post/<id:\d+>/<title:.*?>'=>'post/view',
    'posts/<tag:.*?>'=>'post/index',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
    ),*/
    'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
    array(
    'class'=>'CFileLogRoute',
    'levels'=>'error, warning',
    ),
    // uncomment the following to show log messages on web pages
    /*
    array(
    'class'=>'CWebLogRoute',
    ),
    */
    ),
    ),
    )

    在构造函数中执行configure
    public function configure($config)
    {
    if(is_array($config))
    {
    foreach($config as $key=>$value)
    $this->$key=$value;
    }
    }
    相当于$this->components=array()//config配置文件中的components对应的数组集合;实际上执行ccomponent.php的魔术方法__set

    所以这里会调用一次'set'.$name;//$name=components ,即第3次调用setComponents()


    public function setComponents($components,$merge=true)
    {
    // phptest2($components,__FILE__.__METHOD__.__line__);

    //debug_print_backtrace();
    foreach($components as $id=>$component)
    {
    // echo "id:".$id."; component:".$component."<br/>";
    if($component instanceof IApplicationComponent) //暂时测试没遇到这种情况
    {
    $this->setComponent($id,$component);
    //phptest2("if",__FILE__.__METHOD__.__line__);
    }
    else if(isset($this->_componentConfig[$id]) && $merge) //如果已经存在key,则合并之前的
    {
    $this->_componentConfig[$id]=CMap::mergeArray($this->_componentConfig[$id],$component);
    //phptest2("else if zhoujian $id",__FILE__.__METHOD__.__line__);
    }
    else //新建
    {
    $this->_componentConfig[$id]=$component;
    //phptest2("else",__FILE__.__METHOD__.__line__);
    }
    }
    phptest2($this->_componentConfig,__FILE__.__METHOD__.__line__);
    }

    如果

    爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

    http://biancheng.dnbcw.info/php/339160.html pageNo:8
  • 相关阅读:
    Delphi 学习笔记
    Extjs 4
    面向对象(OOP)
    Java基础
    Ubantu(乌班图)
    CentOS 6.3操作常识
    英语音标单元音篇
    英语音标双元音篇
    英语音标辅音篇
    Oracle补习班第一天
  • 原文地址:https://www.cnblogs.com/ooooo/p/2246180.html
Copyright © 2011-2022 走看看