Redirect to Action with Parameter

Hello,

I had an odd problem where my parameter wasn’t being recognized in an action unless I renamed it.

The thing is, it was working for me perfectly, in production. But a user on Android said it was giving errors.

Here is my redirect code:

From UsersController::load

    return $this->redirect([
        'controller' => 'BankAccounts',
        'action' => 'index',
        $user->id
    ]);

Then in BankAccountsController, I had this:

public function index($user_id)
{
    $user = $this->getUser($user_id);
    // ...
}

For me it worked. For two other users, it did not. I had one help me debug, and it gave a warning that no parameter was passed to the function.

So I changed it to this:

public function index($id = null)
{
    $user = $this->getUser($id);
    // ...
}

And now it works.

But still no idea why. Why does CakePHP care about the name of the variable? And why did it work for me, but not for two other users?

Also, it’s not because of the parameter now being optional. Otherwise it wouldn’t be able to load the user, and I confirmed it is loading the proper user now.

Curious, I would also like to know how something like this could happen, as I’m using custom parameter names all the time, as well D:

I guess it must be related to the request handler somehow; Did you see anything interesting in your error.log?