Unable To Access $_Post And $_Get Variables In View Page

Hi, I am filtering my CGridView table with a _search form that uses $_post method, filtering works just fine, but i want to display those input values in the form on my summary text section but whenever i try, i cant event access the post and get variables even though i can clearly see them in firebug, Please Help… Thank you

my actionAdmin




 */

	public function actionAdmin()

	{

		$model=new Order('search');

                

                $str = "test";

                 

                if(isset($_POST['Order']))

                    {

                   

                              

                       $str.=" ifloop";   

                      

                     

                      

                        if(isset($_POST['Order']['agent'])){

                            

                            $model->agent = $_POST['Order']['agent'];

                            $str.="agent";

                        }

//                        if(!empty($_POST['from_date'])){

//                         

//                            $model->from_date = $_POST['from_date'];

//                          

//                            

//                        }

//                        if(!empty($_POST['to_date'])){

//                            $model->to_date = $_POST['to_date'];

//                            var_dump($_POST['to_date']);

//                            $str.="to";

//                        }

//                       

                    }


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

			'model'=>$model,

                        'str'=>$str

                        

		));

	}



my _search form




<?php

/* @var $this OrderController */

/* @var $model Order */

/* @var $form CActiveForm */

?>


<div class="wide form">


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

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

	'method'=>'post',

)); ?>


	<div class="row">

		<?php echo $form->label($model,'from_date'); ?>

		<?php

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

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

                        'value'=>$model->arrivaldate,  // value comes from cookie after submittion

                         'options'=>array(

                            'showAnim'=>'fold',

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

                             'changeYear'=>true,

                             'changeMonth'=>true,

                             'minDate' => '2000-01-01',      // minimum date

                             'maxDate' => '2099-12-31', 

                        ),

                        'htmlOptions'=>array(

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

                        ),

                    ));

                    ?><br>

	</div>

        

        <div class="row">

		<?php echo $form->label($model,'to_date'); ?>

		<?php

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

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

                        'value'=>$model->arrivaldate,  // value comes from cookie after submittion

                         'options'=>array(

                            'showAnim'=>'fold',

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

                             'changeYear'=>true,

                             'changeMonth'=>true,

                             'minDate' => '2000-01-01',      // minimum date

                             'maxDate' => '2099-12-31', 

                        ),

                        'htmlOptions'=>array(

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

                        ),

                    ));

                    ?><br>

	</div>


	<div class="row">

		<?php echo $form->label($model,'agent_name'); ?>

		<?php

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

                    'name'=>'agentname',

                    'model'=>$model,

                    'attribute'=>'agent_name',

                    // additional javascript options for the autocomplete plugin

                    'options'=>array(

                        'minLength'=>'1',

                        'showAnim'=>'fold',

                        'select'=>"js:function(event,ui){

                               $('#agentname').val(ui.item.value);

                               $('#Order_agent').val(ui.item.id);

                               

                                return false;

                        }"

                    ),

                    'source'=>$this->createUrl("order/autocompleteagent"),

                    'htmlOptions'=>array(

                        'style'=>'height:20px; width:120px',

                         

                    ),

                ));

                ?>

	</div>


	

        

        <div class="row">

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

        </div>


	<div class="row buttons">

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

	</div>


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


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



my admin view page




<?php

/* @var $this OrderController */

/* @var $model Order */


$this->breadcrumbs=array(

	'Orders'=>array('index'),

	'Manage',

);





Yii::app()->clientScript->registerScript('search', "


$('.search-form form').submit(function(){

	$('#order-grid').yiiGridView('update', {

		data: $(this).serialize()

	});

	return false;

});

");


$baseurl = Yii::app()->baseUrl;

$cS = Yii::app()->getClientScript();

$cS->registerScriptFile($baseurl.'/js/customjs.js',  CClientScript::POS_END);




?>


<h1>Manage Orders</h1>





<div class="mymain">

    <div class="leftpane filter">

        

        <?php

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

                'items'=>array(

                    array('label'=>'All Orders','url'=>'admin','items'=>array(

                           array('label'=>'Pending ('.$model->checkStatus(Order::PENDING).')','url'=>  Yii::app()->createUrl('order/status',

                                   array('orderstatus'=>  Order::PENDING)))  ,

                                    array('label'=>'Dispatched ('.$model->checkStatus(Order::DISPATCHED).')','url'=>  Yii::app()->createUrl('order/status',

                                   array('orderstatus'=>  Order::DISPATCHED))) ,

                             array('label'=>'Delivered ('.$model->checkStatus(Order::DELIVERED).')','url'=>  Yii::app()->createUrl('order/status',

                                   array('orderstatus'=>  Order::DELIVERED))) 

                

                    )),

                    

                )

            ))

        ?>

    </div>

    <div class="middlepane" style="width:90%; max-width: 90%; left: 17%">

 

<?php echo $str." ";

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

 var_dump($_GET['ajax']); 

        

?>          

<?php 

$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'order-grid',

	'dataProvider'=>$model->search(),

        'ajaxType'=>'post',

        //'ajaxUpdate'=>false,

	'columns'=>array(

                 array(

                    'name'=>'agent',

                    'type'=>'raw',

                    'value'=> 'CHtml::link(CHtml::encode(Shop::model()->getAgentName($data->agent)),$data->url)',

                   

                ),

                array(

                    'name'=>'name',

                    

                ),

                array(

                    'name'=>'amount',

                    'value'=>'number_format($data->amount, 2, ".", ",")',

                    

                ),

		array(

                    'name'=>'arrivaldate',

                    'value'=>'date("h:i A m/d/Y",($data->arrivaldate))',

                    

                ),

		array(

                    'name'=>'ordernumber',

                    

                ),

                array(

                    'name'=>'status',

                    'value'=>'Order::model()->getOrderStatus($data->status)',

                    

                ),

		

		

	),

)); 

// date_default_timezone_set("Africa/Nairobi");


?>


    </div>

    <div class="righpane" style="left:108%">

        <h2>Filter</h2>

        <div class="search-form">

        <?php $this->renderPartial('_search',array(

                'model'=>$model,

        )); ?>

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

    </div>

</div>




CGridView uses post method in ajax request. Read about it.

Actually I found a way to go about it, i had an issue with my ajax request, anyway thank you for your reply

Hi marcos_gavvy,

Your $_POST[‘from_date’] will never be parsed in the controller unless $_POST[‘Order’] is set.

You can use ‘model’ and ‘attribute’ properties for CJuiDatePicker and CJuiAutocomplete instead of ‘name’ and ‘value’ properties. You should use ‘model’ and ‘attribute’ properties when you want to use those widgets in place of CActiveForm::textFields. (On the other hand, ‘name’ and ‘value’ should be used when you want to replace CHtml::textFields.) Then your controller code will be simpler again.

And I don’t understand why you had to use ‘post’ instead of ‘get’.

Thank You softark, Im using post because i want to access the values in the filter form such that i can display them in summary section of the gridview, or is there a better way of doing it?

What do you mean by "summary section of the gridview"? How do you try to display it?

And, why don’t you access $_GET instead of $_POST?

The section where it says "Displaying {start}-{end} of {count} results"

I want it to be if i want to filter the gridview between a certain date range for example it shows From-{the from date}: To-{the to date} that’s in the _search form inputs

I see.

CBaseListView::summaryText supports {start}, {end}, {count}, {page} and {pages} as the tokens. You could not display a search parameter in it.

http://www.yiiframework.com/doc/api/1.1/CBaseListView#summaryText-detail

But, displaying of the starting date and the ending date is rather simple:




<div id="search_date">

<?php if ($model->start_date != ""): ?>

From <?php echo $model->start_date ?> to <?php echo $model->end_date ?>

<?php else: ?>

&nbsp;

<?php endif; ?>

</div>



And you can update it at the same time along with the grid by ajax:




<?php 

$this->widget('zii.widgets.grid.CGridView', array(

  'id'=>'order-grid',

  'dataProvider'=>$model->search(),

  'ajaxUpdate'=>"search_date",

  ...



http://www.yiiframework.com/doc/api/1.1/CGridView#ajaxUpdate-detail