Yii Framework Forum: Get $_Post Value From View To Be Used In Model/search - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Get $_Post Value From View To Be Used In Model/search Rate Topic: -----

#1 User is offline   Thor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 17-January 13

Posted 17 January 2013 - 06:12 PM

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":($data->fcst_koleksi=="b"?"Baik":($data->fcst_koleksi=="h"?"Hilang":($data->fcst_koleksi=="r"?"Rusak":"undefined")))',
		    'htmlOptions'=> array('style'=>'width:40px;')),
		array ('name'=>'fbperbaikan',
		    'value'=>'$data->fbperbaikan=="T"?"Tidak":($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
0

#2 User is offline   fouss 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 385
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 17 January 2013 - 07:21 PM

Something like this should work with no problem

$criteria->compare('toro',$this->$toro);

Posted Image
0

#3 User is offline   fouss 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 385
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 17 January 2013 - 07:48 PM

$criteria->compare('toro',$this->$toro);


no no no!!! this is for GET variable.... so mistake
Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users