Difference between ActiveRecord and model () in yii?

What is the relationship or difference between ActiveRecord and the model in YII?

I tried to record is_object(CActiveRecord::model('Project'));and expected false, but returned true;

Since the log showed that it was an object, I thought it represented a row in the table, but I could not find any attributes representing coloumns.

Also http://www.yiiframework.com/doc/api/1.1/CActiveRecord#model-detail states that it returns an instance of the class CActiveRecord, but I could not find any table row values ​​in this object.

+5
source share
2 answers

The answer is stated in your documentation model()- this is a class level method, and it:

Returns the old model AR. AR. (- .)

, : $model=CActiveRecord::model('Project');, $model CActiveRecord, :

$allModels = $model->findAll(); // will give you all the models of Project
$someModel = $model->findByPk('pkValue'); // will give you the row with primary key value = pkValue 
$model->deleteAll(); // will delete all the records of Project
// and so on

:

: ( )

, . , , ..... , , , , , . $class:: model() → ().

+8

ActiveRecord - . . , MVC, . , Yii - MVC, ActiveRecord .

-

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;
    }
}

+2
source

All Articles