yii框架学习笔记2
2011-11-12 09:12
615 查看
简介:这是yii框架学习笔记2的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339160' scrolling='no'>
爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具
http://biancheng.dnbcw.info/php/339160.html pageNo:8
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
相关文章推荐
- yii框架学习笔记1
- yii框架学习笔记一
- 【PHP】YII 框架学习笔记
- Yii 框架学习笔记(配置文件)
- yii 学习笔记二 、路由 及 yii框架模版使用
- Yii框架学习笔记
- Yii框架学习笔记(第一天)-执行流程
- yii框架学习笔记
- php框架之美 yii学习笔记之一
- yii框架学习笔记三
- Yii框架-文档学习笔记
- yii框架学习笔记
- Yii框架学习笔记(二)将html前端模板整合到框架中
- yii框架学习笔记
- yii 学习笔记三 、yii框架基础流程和控制器及父类分析
- yii框架设计学习笔记(一)
- yii框架学习笔记2
- Yii框架的学习指南(策码秀才篇)1-1 如何认识Yii framework
- hadoop学习笔记:yarn框架资源相关配置
- 一、Yii框架学习之单选框