Hi, I’m new in Yii,
I have a question
How can we get the value of _POST variable from view to be used in model->search? I want to make a dynamic page for report using CGridView.
I have tried to set criteria on controller actionAdmin but failed, so I tried to set criteria on model/search, but also failed
Here is my code in view/adminreport.php and I tried to passing a parameter to model/search in dataprovider
<?php
if(isset($_POST['LibBuku']['fckd_jnskol'])){
$toro = $_POST['LibBuku']['fckd_jnskol'];
//echo $toro;
}
?>
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'lib-buku-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'fckd_jnskol'); ?>
<?php echo $form->textField($model,'fckd_jnskol',array('size'=>60,'maxlength'=>200)); ?>
<?php echo $form->error($model,'fckd_jnskol'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'lib-buku-grid',
'dataProvider'=>$model->searchreport($toro),
'filter'=>$model,
'columns'=>array(
array ('name'=>'k999a',
'value'=>'$data->k999a',
'htmlOptions'=> array('style'=>'width:80px;')),
array ('name'=>'fdtgl_dtg',
'value'=>'$data->fdtgl_dtg',
'htmlOptions'=> array('style'=>'width:60px;')),
array ('name'=>'fdtgl_sls',
'value'=>'$data->fdtgl_sls',
'htmlOptions'=> array('style'=>'width:60px;')),
array ('name'=>'fckd_jnskol',
'value'=>'$data->fckdJnskol->fckd_jnskol . " " . $data->fckdJnskol->k099l',
'htmlOptions'=> array('style'=>'width:200px;')),
array ('name'=>'fcst_koleksi',
'value'=>'$data->fcst_koleksi=="k"?"Kadaluarsa"<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />$data->fcst_koleksi=="b"?"Baik"<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />$data->fcst_koleksi=="h"?"Hilang"<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />$data->fcst_koleksi=="r"?"Rusak":"undefined")))',
'htmlOptions'=> array('style'=>'width:40px;')),
array ('name'=>'fbperbaikan',
'value'=>'$data->fbperbaikan=="T"?"Tidak"<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />$data->fbperbaikan=="Y"?"Ya":"undefined")',
'htmlOptions'=> array('style'=>'width:40px;')),
array(
'value' => '($data->fdtgl_mts!==null)?"":(CHtml::link(
"<img src=".Yii::app()->request->baseUrl."/images/book.png alt=transfer>",
Yii::app()->createUrl("acquisition/libBuku/transfer", array("knokat"=>$data->knokat,"k999a"=>$data->k999a)), array("target"=>"eksemplar","onclick"=>\'window.open("","eksemplar","width=850,height=600,toolbar=no,scrollbars=yes,resizable=yes")\')))',
'type' => 'raw',
'htmlOptions'=> array('style'=>'width:40px;text-align:center'),
),
/*
'fnkd_lokasi',
*/
array(
'class'=>'CButtonColumn',
'htmlOptions'=> array('style'=>'width:90px;text-align:center;'),
),
),
)); ?>
Here is my model - searchprovider()
public function searchreport($jnskol)
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
//if($jnskol !== null or $jnskol !== '')
// $criteria->compare('fckd_jnskol','"'.$jnskol.'"',true);
//else
$criteria->compare('fckd_jnskol',$this->fckd_jnskol,true);
$criteria->compare('k999a',$this->k999a,true);
$criteria->compare('knokat',$this->knokat);
$criteria->compare('fnno_usul',$this->fnno_usul);
$criteria->compare('fdtgl_input',$this->fdtgl_input,true);
$criteria->compare('fdtgl_usul',$this->fdtgl_usul,true);
$criteria->compare('fdtgl_mts',$this->fdtgl_mts,true);
....
//$criteria->compare('fckd_jnskol',$this->fckd_jnskol,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
action report
public function actionReport()
{
$this->layout='//layouts/column1';
$model=new LibBuku('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['LibBuku']))
$model->attributes=$_GET['LibBuku'];
$this->render('adminreport',array(
'model'=>$model,
));
}
Your help, please
Thank you