Ordering A Model

Hi,

in actionIndex I oredered elements modifying the method using CActiveDataProvider in this way:




public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('Articoli', array(

						'criteria'=>array(

										  'order'=>'id DESC' //'order'=>'data DESC'

										  ),

						));

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

			'dataProvider'=>$dataProvider,

		));

	}



Now I have to accomplish the same ordering in actionAdmin but I have just the model class:




public function actionAdmin()

	{

		$model=new Articoli('search');

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

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

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


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

			'model'=>$model,

		));

	}



How can I order the model?

I thought I could use the array_reverse PHP function on GET but I don’t know what’s GET structure.

Anyway, is there any other way?

Thanks!

A way should be to add the ordering in the CActiveDataProvider produced by the function search() in your model.

My search() function in Model is:




public function search()

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;


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

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

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

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


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

			'criteria'=>$criteria,

		));



You mean I should modify it like this?




public function search()

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;


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

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

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

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


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

			'criteria'=>$criteria,

                        'criteria'=>array(

                                    'order'=>'id DESC'

                                    ),

		          ));






Or can I just remove the ‘criteria’=>$criteria and adding mine?

Or maybe using the “order” property :P

Ok,

I succeed adding a




$criteria->order = 'id DESC';



in search(). Thank you so much!