pioneer
(En Richme)
August 19, 2009, 1:14am
1
Hi everyone,
The sample application generated by Yii shell uses ActiveRecord to query the database.
The pagination works perfectly.
I tried changing it to using DAO but I cant get pagination to work.
Using AR way,
This line of code select the results for a page.
$pages->applyLimit($criteria);
$pages is an instance of CPagination and $criteria is an instance of CDbCriteria.
Using DAO way, I am using CDbCommand.
I can’t use the applyLimit() method in CPagination.
As a result, I get the same data for every page.
I am puzzled. Can I do pagination of the results if I use DAO?
mikl
(Mike)
August 19, 2009, 8:09am
2
If you take a look at the implementation you see, that no magic happens in applyLimit():
public function applyLimit($criteria)
{
$criteria->limit=$this->pageSize;
$criteria->offset=$this->currentPage*$this->pageSize;
}
In order to get the correct page data, you need to add a "LIMIT offset, row_count " clause to your SQL using the same values from $pages as above.
auxbuss
(Apps)
August 20, 2009, 5:33pm
3
Just wanted to say that I’ve changed/extended my framework to circumvent $pages->applyLimit($criteria), because that statement is feature envy, imo (tightly coupling criteria to pagination). As a result, things are also consistent with DAO.