Confusion in Choosing Model Type


I’m a newbie to YII. I have tried few examples which checks the performance of active record, querybuilder and sql dao. Very clearly SQL DAO is the winner. So i’m planning to use it.

My confusion is on the Model being used. As books describe there are two models,

CActiveModel and CFormModel.

However when I ran the comparison all models extended the CActiveModel.

My question is it better to use SQL Dao on CActiveModel or should I update all models to extend CFormModel.

Hi and welcome to the world of Yii

Note that there is no CActiveModel… I guess you was thinking on CActiveRecord, right?

The difference between those two classes are simply explained in the CFormModel documentation -

By your "simple" question I guess you just checked some Yii code here and there without reading any tutorial… I would strongly suggest you to read the Definitive Guide to Yii -

It will give you all the starting information you need to understand the Yii basics.

Quite right. I made the mistake when I first started with Yii of using CFormModel for a form and CActiveRecord to persist the data. It just about doubles the work load and makes maintenance more difficult.

As mdomba says, use CActiveRecord throughout if you’re persisting data from the form to a database. Use CFormModel for things like login forms where you’re just confirming data that the user has entered.

Definitely read the guide.