Hi,
the Yii crud generator creates:
- This line in the adminAction() Controller method:
$model=new FlkActivities(‘search’);
- The method search() inside the FlkActivities Model.
It seems that the method is called automatically, but I am a little bit confused by the syntax new FlkActivities(‘search’) and by the fact that it seems to be called ‘anyway’.
In fact I tried to call new FlkActivities() with no parameter and new FlkActivities(‘mymethod’) but it seems that always the ‘search’ method is called.
Can anyone help me understanding how does it work?
I want to add an ‘order by’ condition to the model used in the controller adminAction() method and the only way I managed to do it is, inside the FlkActivities Model
- Created a scope:
public function scopes()
{
return array(
'ordByNewer'=>array(
'order'=>'pdate DESC',
),
);
}
- Modified the return command inside the search() function from this:
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
to this
return new CActiveDataProvider($this->ordByNewer(), array(
'criteria'=>$criteria,
));
It works, but I would have liked to keep the ordByNewer() scope call outside the search() function. Is there any way to do this?
Thank you,
Andrea