Using Csort With Cactivedataprovider

First of all, thank you for this forum and for all your “free” support. I’m a Yii newbie, so please be gentle with me! :slight_smile:

I’m trying to use CSort within an actionIndex that use CActiveDataProvider, the same activeIndex() of the “Blog” Demo. I’m trying to display a custom “title” sort link within the index.php, and it’s done. I succeed to make it works creating 2 new CSort objects, and I’m sure this is not the right procedure.

This is the actionIndex():




public function actionIndex()

	{

		$criteria=new CDbCriteria(

                    array(

                        'condition'=>'status='.Post::STATUS_PUBLISHED,

                        'with'=>'commentCount',

                    )

                );

                

                

                //Piece of code to create CSort instance...

                if (isset($_GET['sort'])) {

                    $sort = new CSort('Post');

                    $sort->applyOrder($criteria);

                }

                    

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

			$criteria->addSearchCondition('tags',$_GET['tag']);


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

			'pagination'=>array(

				'pageSize'=>Yii::app()->params['postsPerPage'],

			),

			'criteria'=>$criteria,

		));


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

                        'dataProvider'=>$dataProvider,

		));

	}



and these are the rows within the index.php:




<?php

$order = new CSort('Post');

echo $order->link('title', 'Title');

?>



Now, is it possible to make it works better, just creating one CSort instance? I tried to pass the $sort variable to index.php but i can’t succeed.

Thank you!

Hoops…guys, no way to help me?! :slight_smile: