Yii Model Shortcut

Hi guy,

I have the following code:




$criteria = new CDbCriteria;

$criteria->condition = 'ratingAdjustment = 1 AND sortOrder IS NOT NULL';

$criteria->order = 'sortOrder ASC';


$things_you_want = DC::model()->findAll($criteria);



Is there another way to do this so that I can put the logic in DC model and I call DC::model()->getThingsYouWant() for example.

In DC model file, I have




	public static function thingsYouWant()

	{

		$criteria = new CDbCriteria;

		$criteria->condition = 'ratingAdjustment = 1 AND sortOrder IS NOT NULL';

		$criteria->order = 'sortOrder ASC';

		

		return $this->findAll($criteria);

	}



and I call DC::thingsYouWant() which return




Fatal error: Using $this when not in object context in C:\Ampps\www\MPP\protected\models\DC.php on line 94



I am missing something here and I have no clues.

Thanks for helps,

$this is not valid in a static function.

And you have to call Model::model() when ever you want to call find*() functions.

http://www.yiiframework.com/doc/guide/1.1/en/database.ar#reading-record




	public static function thingsYouWant()

	{

		$criteria = new CDbCriteria;

		$criteria->condition = 'ratingAdjustment = 1 AND sortOrder IS NOT NULL';

		$criteria->order = 'sortOrder ASC';

		

		return DC::model()->findAll($criteria);

	}






$thingsYouWant = DC::model()->getThingsYouWant();






public function thingsYouWant()

{

  $criteria = new CDbCriteria;

  $criteria->condition = 'ratingAdjustment = 1 AND sortOrder IS NOT NULL';

  $criteria->order = 'sortOrder ASC';

                

  return $this->findAll($criteria);

}