总是想弄清楚从index到页面显示的所有流程,但是还是没有搞清楚,现在卡在了set('date',$this->Post->findAll())这个语句,因为我不知道Post是如何出现的(我现在用官方的那个blog_tutorial来判断流程),然后找到了controller的构造函数,之后就没有发现如何装载model类。
下面还是直接看tutorial,搞清楚Model View Controller三个类的一些API,能迅速开发,整个框架的源代码还是以后再看吧。
下面是测试一下代码框,就拿controller的构造函数吧
function
__construct ()
{
if ( $this -> name === null )
{
$r = null ;
if ( ! preg_match ( ' /(.*)Controller/i ' , get_class ( $this ) , $r ))
{
die ( " Controller::__construct() : Can't get or parse my own class name, exiting. " );
}
$this -> name = $r [ 1 ];
}
if ( $this -> viewPath == null )
{
$this -> viewPath = Inflector :: underscore( $this -> name);
}
$this -> modelClass = Inflector :: singularize( $this -> name);
$this -> modelKey = Inflector :: underscore( $this -> modelClass);
if ( ! defined ( ' AUTO_SESSION ' ) || AUTO_SESSION == true )
{
$this -> components[] = ' Session ' ;
}
if ( is_subclass_of ( $this , ' AppController ' ))
{
$appVars = get_class_vars ( ' AppController ' );
foreach ( array ( ' components ' , ' helpers ' , ' uses ' ) as $var )
{
if ( isset ( $appVars [ $var ]) && ! empty ( $appVars [ $var ]))
{
$diff = array_diff ( $appVars [ $var ] , $this -> { $var });
$this -> { $var } = array_merge ( $this -> { $var } , $diff );
}
}
}
if ( ! empty ( $this -> components))
{
$component =& new Component( $this );
}
parent :: __construct();
}
{
if ( $this -> name === null )
{
$r = null ;
if ( ! preg_match ( ' /(.*)Controller/i ' , get_class ( $this ) , $r ))
{
die ( " Controller::__construct() : Can't get or parse my own class name, exiting. " );
}
$this -> name = $r [ 1 ];
}
if ( $this -> viewPath == null )
{
$this -> viewPath = Inflector :: underscore( $this -> name);
}
$this -> modelClass = Inflector :: singularize( $this -> name);
$this -> modelKey = Inflector :: underscore( $this -> modelClass);
if ( ! defined ( ' AUTO_SESSION ' ) || AUTO_SESSION == true )
{
$this -> components[] = ' Session ' ;
}
if ( is_subclass_of ( $this , ' AppController ' ))
{
$appVars = get_class_vars ( ' AppController ' );
foreach ( array ( ' components ' , ' helpers ' , ' uses ' ) as $var )
{
if ( isset ( $appVars [ $var ]) && ! empty ( $appVars [ $var ]))
{
$diff = array_diff ( $appVars [ $var ] , $this -> { $var });
$this -> { $var } = array_merge ( $this -> { $var } , $diff );
}
}
}
if ( ! empty ( $this -> components))
{
$component =& new Component( $this );
}
parent :: __construct();
}