The logic of applyLimit to a criteria

I’m quoting from the Blog tutorial: http://www.yiiframework.com/doc/blog/post.admin




public function actionAdmin()

{

    $criteria=new CDbCriteria;

 

    $pages=new CPagination(Post::model()->count());

    $pages->applyLimit($criteria);

    ...

}



What I see happening here is that the CPagination object is used to set a variable in the CDbCriteria (limit).

Is it just me or does this seem very backward? Wouldn’t it be more natural to have a function in CDbCriteria that has limit as argument, ie. $criteria->setLimit(Post::model()->count()) ?

Thanks for any feedback, trying to grasp the logic here :)

Indeed its just you. :) You can manually set the limit of the criteria object.




$c->limit = 10;



hehe ;)

OK, so it can be done, then why isn’t it done this way? Seem much more logic to set the limit directly in the criteria object, than sending the criteria object to another object and setting it there, no?

The same "opposite" (to me) logic is used in the default controller made by yiic:




$sort=new CSort('items');

$sort->applyOrder($criteria);