Pencarian Melalui Form


(Mrkoeh) #1

permisi gan,

saya mau tanya. .

saya bikin pencarian data di cgridview, sperti ini penampakannya. .

4172

Capture.PNG

lha yg saya tanyakan, gmna cara buat ngirim variabel2 dari form diatas gan??

terimakasih. . .

#tanggal menggunakan datepicker, textfield milih dari cjuidialog. .


(Ocimzone) #2

ikut nyimak gan  <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/grin.gif' class='bbc_emoticon' alt=';D' /> 


(Jimmi Nababan) #3

mungkin lebih baik kalau disertakan dengan kode.

dan biasanya ini bermainnya diseputaran model.

ngirimnya pake ajax, form nya di form _search

coba lihat fungsi search yang ada di model, dan perhatikan kodenya.


(Mrkoeh) #4

_search.php




<?php

/* @var $this PendapatanBaruController */

/* @var $model PendapatanBaru */

/* @var $form CActiveForm */

?>


<div class="wide form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'action'=>Yii::app()->createUrl($this->route),

	'method'=>'get',

)); ?>


	<table>

	<tr>

		<td><b>Periode</b></td>

		<td> : </td>

		<td>

			<?php

			$this->widget('zii.widgets.jui.CJuiDatePicker', array(

				'name'=>'tgl_awal',  // name of post parameter

				'value'=>isset(Yii::app()->request->cookies['tgl_awal']) ? Yii::app()->request->cookies['tgl_awal'] : '',

				 'options'=>array(

					'showAnim'=>'fold',

					'dateFormat'=>'yy-mm-dd',

				),

				'htmlOptions'=>array(

					'style'=>'height:20px;'

				),

			));

			?>

		</td>

		<td><center><b> s/d </b></center></td>

		<td>

			<?php

			$this->widget('zii.widgets.jui.CJuiDatePicker', array(

				'name'=>'tgl_akhir',

				'value'=>isset(Yii::app()->request->cookies['tgl_akhir']) ? Yii::app()->request->cookies['tgl_akhir'] : '',

				 'options'=>array(

					'showAnim'=>'fold',

					'dateFormat'=>'yy-mm-dd',

				),

				'htmlOptions'=>array(

					'style'=>'height:20px;'

				),

			));

			?>

		</td>

	</tr>

	<tr>

		<td><b>Dokter </b></td>

		<td> : </td>

		<td>

			<input type="hidden" name="id_text" id="id_text" />

			<input type="text" readonly="readonly" name="nama_text" id="nama_text" />  

		</td>

		<td>

			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#nama_text").val("");$("#id_text").val("")')) ?>

			<?php echo CHtml::Button('Get Dokter',  

					array('onclick' => '$("#dialogdokter").dialog("open"); return false;',  

				));  

			?>

		</td>

	</tr>

	<tr>

		<td><b>Unit Pelayanan </b></td>

		<td> : </td>

		<td>

			<input type="hidden" name="id_layanan" id="id_layanan" />

			<input type="text" readonly="readonly" name="nama_layanan" id="nama_layanan" />  

		</td>

		<td>

			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#nama_layanan").val("");$("#id_layanan").val("")')) ?>

			<?php echo CHtml::Button('Get Layanan',  

					array('onclick' => '$("#dialogpelayanan").dialog("open"); return false;',  

				));  

			?>

		</td>

	</tr>

</table>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Search'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- search-form -->


<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

	'id'=>'dialogdokter',

	'options'=>array(

		'title'=>'Daftar Dokter',

		'autoOpen'=>false,

		'modal'=>true,

		'width'=>550,

		'height'=>470,

	),

)); 

echo $this->renderPartial('loadDokter', array('model'=>$model));

?>

<div class="divForForm"></div>

<?php $this->endWidget();?>


<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

	'id'=>'dialogpelayanan',

	'options'=>array(

		'title'=>'Daftar Layanan',

		'autoOpen'=>false,

		'modal'=>true,

		'width'=>550,

		'height'=>470,

	),

)); 

echo $this->renderPartial('loadPelayanan', array('model'=>$model));

?>

<div class="divForForm"></div>

<?php $this->endWidget();?>



controller:




public function actionCariDetail()

	{

		$model=new ViewPendapatan('searchdetail');

		$model->unsetAttributes(); // clear any default values

		if(isset($_GET['ViewPendapatan']))

			$model->attributes=$_GET['ViewPendapatan'];

			$this->renderPartial('admin',array(

				'model'=>$model,

			),false,true);


		Yii::app()->end();

	}



model:




public function searchdetail($tgl_awal,$tgl_akhir,$kd_dokter,$kd_pelayanan)

	{

		$criteria=new CDbCriteria;

		$criteria->addBetweenCondition('tanggal',$tgl_awal,$tgl_akhir,'AND');

		$criteria->addCondition('id',$kd_dokter);

		$criteria->addSearchCondition('unit_pelaksanaa', $kd_pelayanan);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}



ini gan sourcecodeny. . .


(Jimmi Nababan) #5

kalau yang ditanya bagaimana mengirimnya, masukin aja fieldnya di form _search file itu,

link dengan modelnya, click search pasti langsung bisa, sama seperti yang advance mode form.

adakah error yang dihasilkan dari kode dibawah ini ?

cara tergampang, ubah file _search nya, lalu lihat perubahannya.


(Mrkoeh) #6

iya gan, udah solved. .

kmren saya gak kepkiran, trus ternyata ad file yang salah panggil jadi gak bisa menghasilkan ap2. .

terimkasih atas fast responnya. .

ini di _search :




<?php

/* @var $this PendapatanBaruController */

/* @var $model PendapatanBaru */

/* @var $form CActiveForm */

?>


<div class="wide form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'action'=>Yii::app()->createUrl($this->route),

	'method'=>'get',

)); ?>


	<table>

	<tr>

		<td><b>Periode</b></td>

		<td> : </td>

		<td>

			<?php

			$this->widget('zii.widgets.jui.CJuiDatePicker', array(

				'name'=>'ViewPendapatan[tgl_awal]',  // name of post parameter

				//'value'=>isset(Yii::app()->request->cookies['ViewPendapatan[tgl_awal]']) ? Yii::app()->request->cookies['ViewPendapatan[tgl_awal]'] : '',

				  'value' => $model->tgl_awal,

				 'options'=>array(

					'showAnim'=>'fold',

					'dateFormat'=>'yy-mm-dd',

					'changeMonth'=> 'true',

					'changeYear'=> 'true',

				),

				'htmlOptions'=>array(

					'style'=>'height:20px;'

				),

			));

			?>

		</td>

		<td><center><b> s/d </b></center></td>

		<td>

			<?php

			$this->widget('zii.widgets.jui.CJuiDatePicker', array(

				'name'=>'ViewPendapatan[tgl_akhir]',

				//'value'=>isset(Yii::app()->request->cookies['ViewPendapatan[tgl_akhir]']) ? Yii::app()->request->cookies['ViewPendapatan[tgl_akhir]'] : '',

				 'value' => $model->tgl_akhir,

				 'options'=>array(

					'showAnim'=>'fold',

					'dateFormat'=>'yy-mm-dd',

					'changeMonth'=> 'true',

					'changeYear'=> 'true',

				),

				'htmlOptions'=>array(

					'style'=>'height:20px;'

				),

			));

			?>

		</td>

	</tr>

	<tr>

		<td><b>Dokter </b></td>

		<td> : </td>

		<td>

			<?php echo $form->hiddenField($model,'id'); ?>

			<?php echo $form->textField($model,'nama'); ?>

		</td>

		<td>

			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#ViewPendapatan_nama").val("");$("#ViewPendapatan_id").val("")')) ?>

			<?php echo CHtml::Button('Get Dokter',  

					array('onclick' => '$("#dialogdokter").dialog("open"); return false;',  

				));  

			?>

		</td>

	</tr>

	<tr>

		<td><b>Unit Pelayanan </b></td>

		<td> : </td>

		<td>

			<?php echo $form->hiddenField($model,'id'); ?>

			<?php echo $form->textField($model,'unit_pelaksanaa'); ?>

		</td>

		<td>

			<?php echo CHtml::Button('x', array('name' => 'del_people', 'id' => 'del_people', 'onclick' => '$("#ViewPendapatan_unit_pelaksanaa").val("");$("#ViewPendapatan_id").val("")')) ?>

			<?php echo CHtml::Button('Get Layanan',  

					array('onclick' => '$("#dialogpelayanan").dialog("open"); return false;',  

				));  

			?>

		</td>

	</tr>

</table>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Search'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- search-form -->


<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

	'id'=>'dialogdokter',

	'options'=>array(

		'title'=>'Daftar Dokter',

		'autoOpen'=>false,

		'modal'=>true,

		'width'=>550,

		'height'=>470,

	),

)); 

echo $this->renderPartial('loadDokter', array('model'=>$model));

?>

<div class="divForForm"></div>

<?php $this->endWidget();?>


<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog

	'id'=>'dialogpelayanan',

	'options'=>array(

		'title'=>'Daftar Layanan',

		'autoOpen'=>false,

		'modal'=>true,

		'width'=>550,

		'height'=>470,

	),

)); 

echo $this->renderPartial('loadPelayanan', array('model'=>$model));

?>

<div class="divForForm"></div>

<?php $this->endWidget();?>



ini di model:




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

		

		if((isset($this->tgl_awal) && trim($this->tgl_awal) != "") && (isset($this->tgl_akhir) && trim($this->tgl_akhir) != ""))

			$criteria->addBetweenCondition('tanggal', ''.$this->tgl_awal.'', ''.$this->tgl_akhir.'');


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

		$criteria->compare('tanggal',$this->tanggal,true);

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

		$criteria->compare('nama',$this->nama,true);

		$criteria->compare('unit_pelaksanaa',$this->unit_pelaksanaa,true);

		$criteria->compare('nama_ruangan',$this->nama_ruangan,true);

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

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

			

		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}