Date Range Passed To Controller Function

I would like to pass a date range to my Controller function (an excel report), but am not sure how to do it.

My view file has the following code:

In my menu I call the function as usual:


array('label'=>'Export Fee Earner Report', 'url'=>array('FearnerExcel', 'fid'=>$model->id, 'sdate1'=>$sdate1, 'edate1'=>$edate1))

And also in my view file I have the start and end date Datepickers for selection:


	<div class="row">

		<?php $this->widget('zii.widgets.jui.CJuiDatePicker', 

			array(

				'name' => 'sdate1',

				'options'=> array(

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

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

					'changeMonth' => true,

					'changeYear' => true,

//					'yearRange'=>'1900:2050',

					'appendText' => 'yyyy-mm-dd',

				),

			)); 

		?>

	</div>

	<div class="row">

		<?php $this->widget('zii.widgets.jui.CJuiDatePicker', 

			array(

				'name' => 'edate1',

				'options'=> array(

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

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

					'changeMonth' => true,

					'changeYear' => true,

//					'yearRange'=>'1900:2050',

					'appendText' => 'yyyy-mm-dd',

				),

			));

		?>

	</div>



with the same names sdate1 & edate1 as in my menu.

However even if I select the dates and then select the report menu function, updated values are not passed?

How could I make the menu sdate1 & edate1 be updated dynamically through the Datepickers?

just create a form and put these dates inside form give the action to your controller/action , there you can access using date name which u are giving for date

or

create an ajax call to post the the date to controller function.

How do I make an ajax call to post the date to the controller function? I thought the Datepicker was already an ajax call?

Hi.

First, set the id to sdate1 and edate1 datapicker.

In your view:




<script>

// "url" must be an controller action.

function updateDates(url, fid)

{

     var lData = {"sdate1" : $("#sdate1").val(), 

                  "edate1" : $("#edate1").val(),

                  "fid" :fid};


     $.ajax({

          'url' : url,

          'type' : 'POST',

          'dataType' : 'json',

          'data' : lData,

          'success' : function (data){alert(data);},

          'error' : function (data){alert(data);}

     });

}

</script>



Make a button or link and assign it the function updateDates to the onlick event (send the url and the fid).

Then, in your action update the dates an go.

For example:




public function actionUpdateDates()

{

     // Get POST values and update your model.


     // If update was OK, return "yuhuuuu!"

     echo("yuhuuuu!");


     // If update was wrong, return "ouch!"

     echo("ouch!");

}



Greetings.

Thanks for all the replies. I couldn’t get the ajax call working, but created a new form and got it working.