Welcome Guest, Not a member yet? Register   Sign In
Auto Routing Improved doesn't work for getIndex with parameters
#1
Question 

I enabled Auto Routing improved and trying to follow the manuals. I want to add pagination to my clients list:
  • /clients/13 - page 13
  • /clients/1 - page 1
Code:
<?php

namespace App\Controllers;

class Clients extends BaseController
{
    public function getIndex($page = 1)
    {
      //TODO
      return view('clients/index', $data);
    }
}


However even with auto routing enabled /clients/13 results in error 404
Reply
#2

(This post was last modified: 01-17-2023, 07:05 PM by kenjis.)

Sorry, you can't do like that.
Because the URI corresponding to default method (index) must be omitted.
In other words, you cannot have parameters in `getIndex()`.

If you want to go `/clients/13`, you need to have `get13()` method in your controller.

If you have `getP($page = 1)` method, you can go `/clients/p/13`.
Reply
#3

(This post was last modified: 01-25-2023, 09:07 PM by Rinart.)

My bad. When I just discovered CodeIgniter I didn't know it already has a pagination class. https://codeigniter.com/user_guide/libra...ation.html
Reply
#4

No problem.

I sent an enhancement PR for Auto Routing Improved.
See https://github.com/codeigniter4/CodeIgniter4/pull/7162
Reply




Theme © iAndrew 2016 - Forum software by © MyBB