Php paging usage (from yii Framework)

Source: Internet
Author: User
Php paging usage (from yii Framework)

  1. Php; toolbar: false ">/* public function actionReport ()
  2. {
  3. $ SQL = "select * from {goods }}";
  4. $ Criteria = new CDbCriteria ();
  5. $ Result = Yii: app ()-> db-> createCommand ($ SQL)-> query ();
  6. $ Pages = new CPagination ($ result-> rowCount );
  7. $ Pages-> pageSize = 2;
  8. $ Pages-> applyLimit ($ criteria );
  9. $ Result = Yii: app ()-> db-> createCommand ($ SQL. "LIMIT: offset,: limit ");
  10. $ Result-> bindValue (': offset', $ pages-> currentPage * $ pages-> pageSize );
  11. $ Result-> bindValue (': limit', $ pages-> pageSize );
  12. $ GoodsInfo = $ result-> query ();
  13. $ This-> render ('index', array (
  14. 'Goodsinfo' => $ goodsInfo,
  15. 'Pages '=> $ pages,
  16. ));
  17. }*/

  1. Foreach ($ goodsInfo as $ v ){
  2. }
  3. ?>
  4. ?>
  5. // Pagination widget code:
  6. $ This-> widget ('clinkpager', array ('page' => $ pages ));
  7. ?>
  8. Item name Price Update Time

Method 2: Use your own paging class to complete paging 1. Controller code:

  1. Public function actionIndex (){

  2. $ Goods_m = goods: model ();

  3. // 1. obtain the total number of records for the product

  4. $ Cnt = $ goods_m-> count ();

  5. // 2. instantiate a paging object

  6. $ Page = new Page ($ cnt, 2 );

  7. // 3. re-assemble the SQL statement according to the paging style for query

  8. $ SQL = "select * from {goods} $ page-> limit ";
  9. $ GoodsInfo = $ goods_m-> findAllBySql ($ SQL );

  10. // 4. obtain the page List (to be displayed in the view template)

  11. $ PageList = $ page-> fpage ();

  12. $ This-> renderPartial ('index', array ('goodsinfo' => $ goodsInfo, 'pagelist' => $ pageList ));

  13. }

2. View code:

  1. Foreach ($ goodsInfo as $ v ){
  2. }
  3. ?>
  4. ?>
  5. Echo $ pageList;
  6. ?>
  7. Item name Price Create_time

The paging class should be placed in a directory that can be automatically loaded;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.