duanqin2026 2015-11-05 05:34
浏览 39
已采纳

具有不同页码的多个分页

I am using CakePHP 2.5.x. In single request I am calling paginate() method twice. In first call, I do not need page parameter as I am selecting all records for that.

For second call of paginate(), I am selecting data based on page parameter found in URL.

Now, concern is that:

http://localhost/xyz/home/get_data/page:1   //working fine
http://localhost/xyz/home/get_data/page:2   //throw 404 from first paginate()

What will be good way to omit page param for first paginate() call.

P.S. I am using same model for both paginate() call.

Point me if it's duplicate. Thank you in advance.

  • 写回答

1条回答 默认 最新

  • douxuan3095 2015-11-05 07:00
    关注

    I figured out way to solve the problem. Here are steps I am following for first paginate() call (where the actual issue exist)

    1. I save original page param from url in another variable
    //get original page number from request and set first page manually
    $original_page_number = !empty($this->request->params['named']['page']) ? $this->request->params['named']['page'] : 1;
    $this->request->params['named']['page'] = 1;
    1. Call paginate() function

    2. Reassign original page param to request object

    //set back to original page number
    $this->request->params['named']['page'] = $original_page_number;

    As I have problem in first paginate() call, so I omitted page param for that call only.

    Hope it will help someone!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂