CListView update via ajax

I’ve made a CListView update which works fine. The code is:





    public function actionFilterItems()       

    {

        

        $criteria = new CDbCriteria;


        if (isset($_POST['gender']) && !empty($_POST['gender'])) {

            $criteria->addInCondition('gender', CJSON::decode($_POST['gender'], false));

        }

        

        $criteria->order = 'itemBasePrice ASC'; 

        

        $dataProvider =  new CActiveDataProvider(inShopItem::model()->active(), array(

            'criteria'=>$criteria,

            'pagination' => array (

                'pageSize' => Yii::app()->user->getState('pageSize', 20),

            ),

        ));

        

        

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

            'dataProvider'=>$dataProvider,

        ));                

    }




I make an update every time a filter checkbox is checked|unchecked. But I want to refresh filter values for every new set of listed items, like colour, brand and so on. How can I pass additional data back to view to rearrange filters? I’ve tried $this->colour so that to access it in the view, but its value remains unchanged.

I wonder why $this doesn’t work? And that is not the first time I can’t access $this in the view, rendered by controller, where $this was populated with some value;

Would much appreciate any help.

Hi,

you should use CController::render method’s second parameter for passing any additional data into your views. For example:




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

  'dataProvider'=>$dataProvider,

  'colour'=>$colour,

));



So in your view you will have new variable called $colour.

I did so, but with no result, unfortunately.

Your controller action code should look like this:


public function actionFilterItems()

{


  $criteria = new CDbCriteria;


  if (isset($_POST['gender']) && !empty($_POST['gender'])) {

    $criteria->addInCondition('gender', CJSON::decode($_POST['gender'], false));

  }


  $criteria->order = 'itemBasePrice ASC';


  $dataProvider =  new CActiveDataProvider(inShopItem::model()->active(), array(

            'criteria'=>$criteria,

            'pagination' => array (

                'pageSize' => Yii::app()->user->getState('pageSize', 20),

  ),

  ));

  

  $colour = 'red';//added this line


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

            'dataProvider'=>$dataProvider,

            'colour'=>$colour,//added this line

  ));

}



And in view index.php you shouldn’t have any problems getting $colour variable value, like this:




<?php echo "Colour: $colour"; ?>



This must work.