Hi Yii Master, i’m newbie in Yii…
I have problem about Cgridview which is rendered using renderPartial inside of CJuitabs.
Here’s the CJuitabs (index.php):
$prodi=$this->renderPartial('pages/_tabProdi', NULL, $return=true);
$aak=$this->renderPartial('pages/_tabAAK',NULL,$return=true);
$au=$this->renderPartial('pages/_tabAU',NULL,$return=true);
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array(
'Program Studi (Prodi)'=>array('content'=>$prodi, 'id'=>'prodi'),
'Administrasi Akademik & Kemahasiswaan (AAK)'=>array('content'=>$aak, 'id'=>'aak'),
'Administrasi Umum (AU)'=>array('content'=>$au, 'id'=>'au'),
),
// additional javascript options for the tabs plugin
'options'=>array(
'collapsible'=>false,
'event'=>'mouseover',
),
));
i have 3 CGridview files (_tabProdi.php, _tabAAK.php and _tabAU.php)
and here’s one of them (_tabProdi.php):
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'_tabProdi',
'dataProvider' => $model->search(), //error in here
'filter' => $model,
'summaryText' => 'Menampilkan {start} - {end} dari total {count} data',
'pager' => array(
'header' => 'Halaman ',
'nextPageLabel' => 'Selanjutnya',
'prevPageLabel' => 'Sebelumnya',
'firstPageLabel' => 'Awal',
'lastPageLabel' => 'Akhir',
'maxButtonCount' => 3,
),
'columns' => array(
array(
'header' => 'NIK',
'name' => 'NIK',
'type' => 'raw',
'value' => 'CHtml::encode($data->NIK)'
),
array(
'header' => 'NAMA',
'name' => 'NAMA',
'type' => 'raw',
'value' => 'CHtml::encode($data->NAMA)',
),
array(
'header' => 'FAKULTAS',
'name' => 'FAKUL_ID',
'type' => 'raw',
'value' => 'CHtml::encode($data->FAKUL_ID)',
),
array(
'name' => 'EMAIL',
'type' => 'raw',
'value' => 'CHtml::encode($data->em->EMAIL)',
),
),
));
here’s the model (User.php):
class User extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'KAR_MF';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('NIK, NAMA, FAKUL_ID, STATUS', 'required'),
);
}
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(
'em'=>array(self::HAS_ONE,'MailStaf','NIK'),
'ua'=>array(self::HAS_ONE,'UserApp','NIK'),
);
}
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$notin='123456';
$criteria=new CDbCriteria;
$criteria->condition = "NIK NOT IN $notin";
$criteria->compare('NIK',$this->NIK,true);
$criteria->compare('NAMA',$this->NAMA,true);
$criteria->compare('FAKUL_ID',$this->FAKUL_ID,true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'NIK ASC',
),
'pagination'=>array(
'pageSize'=>5
),
));
}
}
in some threads, i have to create controller like this:
public function actionUser() {
$model =new User('search');
if(isset($_GET['User']))
$model->attributes =$_GET['User'];
$params =array(
'model'=>$model,
);
if(!isset($_GET['ajax'])) $this->render('user', $params);
else $this->renderPartial('user', $params);
}
but, it works if i call actionUser (user.php). How is about index.php (containing CGridView via renderPartial() inside of CJuiTabs)
i’ve got error:
Fatal error: Call to a member function search() on a non-object in C:\xampp\....
Sorry for my poor English.
Thank you for your answer.