Model CModel loosely coupled

widget for presentation

The main job of a model in Yii is to be used with forms. So it provides help if you want to assign form data into attribute values, validate this data and store error messages per attribute.

You always can create your custom models - as long as they are in protected/models and have filename=classname you can use them everywhere. Yii will load them automatically. But the question is: Do you really need a model then?

Which task are your custom models for?

Then it’s better to extend from CModel.

Not sure if i understand. But you can enhance e.g. the ActiveRecords you have with additional getters and do the "crunching" inside:




public function getContentTeaser($length=100,$suffix='...')

{

    return mb_strlen($this->content)<=$length) ? $this->content : (substr($this->content,0,$length) . $suffix);

}

My AR models are usually full of things like these. If you do lengthy calculations you could also add a private property to store the result, in case you frequently access it during one request.

The way I see it (but I am a newby as you can see ;) ), using ActiveRecord makes sense mainly when you need to insert/modify or otherwise work with single records. If you just need to select and display database data, I would recommend CSqlDataProvider.

I’m in a similar situation building a reporting application that doesn’t change data. I’ve ended up with a CFormModel descendant, because each report has some selection parameters in a form, but the model has a report() method, which returns the dataset (much like the search() method in an ActiveRecord model).

Hope it helps.