How to use Pagination with findAllBySql?

I have this situation where I have a complex query that is easier to handle with findAllBySql.

Now my problem is that I can’t use Pagination, maybe I am missing something.

I can’t seem to be able to apply the limit, so I get all the records in my query.




$total = anuncio::model()->countBySql($q);

$paginas = new CPagination($total);

$paginas->pageSize = 10;

$paginas->applyLimit($q);   // <-- how do I apply the limit to my sql statement?

$anuncios = anuncio::model()->findAllBySql($q);



How do I use Pagination with findAllBySql?

Thank you.

You can add a " LIMIT $offset,$limit" to your SQL manually. See the implementation of applyLimit() on how to get these two values:

http://code.google.com/p/yii/source/browse/tags/1.0.10/framework/web/CPagination.php#162

Thanks mike for sharing this post…

i have check this thread and try to implement it.but one this is not clear to me that how could i get a current page.


 $criteria->offset=$this->currentPage*$this->pageSize;



so that it work correctly…!!

thank in advance…