总是想弄清楚从index到页面显示的所有流程,但是还是没有搞清楚,现在卡在了set('date',$this->Post->findAll())这个语句,因为我不知道Post是如何出现的(我现在用官方的那个blog_tutorial来判断流程),然后找到了controller的构造函数,之后就没有发现如何装载model类。

下面还是直接看tutorial,搞清楚Model View Controller三个类的一些API,能迅速开发,整个框架的源代码还是以后再看吧。

下面是测试一下代码框,就拿controller的构造函数吧
 

最近看的项目cakephp   function __construct ()
最近看的项目cakephp    {     
最近看的项目cakephp        
if($this->name === null)
最近看的项目cakephp        {         
最近看的项目cakephp            
$r = null;
最近看的项目cakephp            
if (!preg_match('/(.*)Controller/i', get_class($this), $r))
最近看的项目cakephp            {
最近看的项目cakephp                
die("Controller::__construct() : Can't get or parse my own class name, exiting.");
最近看的项目cakephp            }            
最近看的项目cakephp            
$this->name = $r[1];
最近看的项目cakephp        }
最近看的项目cakephp        
if ($this->viewPath == null)
最近看的项目cakephp        {
最近看的项目cakephp            
$this->viewPath = Inflector::underscore($this->name);
最近看的项目cakephp        }
最近看的项目cakephp
最近看的项目cakephp        
$this->modelClass = Inflector::singularize($this->name);
最近看的项目cakephp        
$this->modelKey  = Inflector::underscore($this->modelClass);        
最近看的项目cakephp          
最近看的项目cakephp        
if(!defined('AUTO_SESSION'|| AUTO_SESSION == true)
最近看的项目cakephp        {
最近看的项目cakephp            
$this->components[] = 'Session';
最近看的项目cakephp        }
最近看的项目cakephp
最近看的项目cakephp        
if (is_subclass_of($this, 'AppController'))
最近看的项目cakephp        {
最近看的项目cakephp            
$appVars = get_class_vars('AppController');             
最近看的项目cakephp            
foreach(array('components', 'helpers', 'uses'as $var)
最近看的项目cakephp            {
最近看的项目cakephp                
if (isset($appVars[$var]) && !empty($appVars[$var]))
最近看的项目cakephp                {
最近看的项目cakephp                 
$diff = array_diff($appVars[$var], $this->{$var});
最近看的项目cakephp                    
$this->{$var= array_merge($this->{$var}, $diff);
最近看的项目cakephp                }
最近看的项目cakephp            }                             
最近看的项目cakephp        }
最近看的项目cakephp        
if (!empty($this->components))
最近看的项目cakephp        {
最近看的项目cakephp            
$component =& new Component($this);
最近看的项目cakephp        }
最近看的项目cakephp        parent
::__construct();             
最近看的项目cakephp    }
最近看的项目cakephp

相关文章: