Yii Framework Forum: Mendapatkan $_Post Pada Model Search - Yii Framework Forum

Jump to content

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

Mendapatkan $_Post Pada Model Search Rate Topic: -----

#1 User is offline   Thor 

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

Posted 17 January 2013 - 04:11 AM

Hi, saya baru belajar serius menggunakan Yii,
saya ada pertanyaan, semoga dapat dibantu

Bagaimana caranya kita bisa mendapatkan isi variabel _POST dari view untuk digunakan pada model->search? Saya ingin membuat report
Saya sudah mencoba untuk set criteria pada controller actionAdmin namun gagal sehingga saya mencoba untuk set criteria pada model search, namun hal ini juga gagal

Saya membuat form di view/adminreport.php dan berupaya melakukan passing ke model->search di 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;'),
		),
	),
)); ?>



berikut adalah model - searchprovider() saya
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 saya sebagai berikut
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,
		));
	}


Mohon bantuannya
Terima kasih
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