* TAccount.php
class TAccount extends CActiveRecord
{
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'cat'=>array(self::BELONGS_TO,'TCatAccount','catid),
);
}
}
* TCatAccount.php
class TCatAccount extends CActiveRecord
{
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'account' => array(self::HAS_MANY,'TAccount','catid'),
);
}
}
and then i call activerecord data :
$model= TActakun::model()->with('cat')->findAll();
// next procedure
public function actionCoa(){
$model= TAccount::model()->with('cat')->findAll();
print_r($model);
if(isset($_GET['TAccount']))
$model->attributes=$_GET['TAccount'];
$this->render('admin',array('model'=>$model));
}
You misunderstood the meaning of $model->search().
Check the code Gii generates. $model is the filter instance (new empty instance or populated with what’s subsequently posted from the search form). When calling search() in the model TAccount, the filter instance is used in building the criteria, the type of $model is used for parameter 1 to the CActiveDataProvider constructor.
In your case, add the with part to the criteria in the search() method of TAccount. Note that search() will return a CActiveDataProvider instance.
If you don’t need search functionality you can do like this and just pass $provider to the dataProvider property of CGridView (omit the filter property):
As a side note, you can achieve a similar array of models like what’s returned from findAll() in your controller example by calling $provider->getData(true).
In the ancient days of Yii 1.0 we added discrete pieces of code in the controller, like criteria, pagination and sort objects, making a count() call to establish pagination as well as offset and limit to the criteria, finally calling findAll() in order to get the array of AR objects. All of this is now handled inside CActiveDataProvider and placed in the models search() method.