I was wondering if there was any differences (performances?) between:
return Client::model()->findAll('type=:type', array(':type' => $type));
$dataProvider = new CActiveDataProvider('Client', array(
'criteria' => array('condition' => 'type=' . $type,)));
I mean what are the pros and cons of using one or the other ?
CActiveDataProvider is a wrapper for CActiveRecord with extended capabilities of sorting, pagination and filtering. Typically CActiveDataProvider is being used in conjunction with zii widgets like CListView or CGridView which are utilizing its sort and search capabilities. So if you want to display data in terms of list or table with (optional) sorting/filtering/pagination - most convenient way of doing it in Yii is using described zii widgets or their extensions.
If you just need to fetch data and use it in any other way, but without smart rendering mechanisms provided by CListView or CGridView - use CActiveRecord, because it doesn’t perform anything else except of fetching of data.
Thanks MadAnd, that makes perfect sense.
I actually ran a test and the findAll() solution is much faster (seems logical since you said CActiveDataProvider is a wrapper).
No problem. Welcome to community!
hi friends you can find records from database by :
$model=name of model::model()->findAll(array(