Home > Backend Development > PHP Tutorial > model()怎么理解?

model()怎么理解?

WBOY
Release: 2016-06-23 14:18:16
Original
1012 people have browsed it

YII中有这样一段代码,$post=Post::model()->findByAttributes($attributes,$condition,$params);
     Post::model()->find()->attributes。
这里的model()改如何理解啊


回复讨论(解决方案)

model覆盖了父类方法,实例化这个类的对象。
你的例子,也就是说model()实例了Post这个类的实例
findByAttributes这个方法也在父类里。

//这个是ar类里的方法。public static function model($className=__CLASS__){    if(isset(self::$_models[$className]))        return self::$_models[$className];    else    {        $model=self::$_models[$className]=new $className(null);        $model->_md=new CActiveRecordMetaData($model);        $model->attachBehaviors($model->behaviors());        return $model;    }} 
Copy after login

Post::model() 返回一个指定的对象

model方法返回POST类的实例。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template