0
votes

Why iam getting a "Missing Route" error for a function that not exists.

Inside Reservations Controller I have function add with one argument:

public function add($carid = null)
{
... 
}

Matching route:

Router::scope('/', function ($routes) {
Router::connect('/rentcar/:id', ['controller' => 'Reservations', 'action' => 'add'],['pass' => ['id'], 'id' => '[0-9]+']);
// rest of the routes not important 
...
});
Plugin::routes();

When I visit any page I see the following error:

http://i.stack.imgur.com/ESX5I.jpg

The error message says:

Error: A route matching "array ( 'controller' => 'Reservations', 'action' => 'add', 'plugin' => NULL, '_ext' => NULL, )" could not be found.

...which is strange because I dont have function add() without arguments, instead, I have function add($carid) with one argument.

But when i add that route, everything works fine:

Router::connect('/rentcar2', ['controller' => 'Reservations', 'action' => 'add']);

What is going on?

1
When receiving errors, always post the exact and complete error message including the corresponding stacktrace! Also check stackoverflow.com/questions/29782797/…, it's probably pretty much the same problem, you are somewhere trying to build a URL for the reservations/add action without passing an id. - ndm
@ndm There is an image above showing the exact and complete error message that i receive. and concerning that question, it's not the same, and conerning what you said about the URL for reservations/add, here is my code: <?= $this->Html->link(__('Reservation'), ['controller' => 'Reservations','action' => 'add', $car->id]) ?> - Br.sasa
It shows the message but it's lacking the stacktrace. Without the latter it's impossible to tell where the problematic call can actually be found. - ndm
@ndm The desired action reservations/add($carid) is NOT being called from the current controller reservations,but from cars controller, that's why i specify a complete URL for the add($carid) function : <?= $this->Html->link(__('Reservation'), ['controller' => 'Reservations','action' => 'add', $car->id]) ?, but cakePHP doesn't recognize the passed parameter $car->id so that it match it with the route Router::connect('/rentcar/:id', ['controller' => 'Reservations', 'action' => 'add'],['pass' => ['id'], 'id' => '[0-9]+']); - Br.sasa
The URL array you are showing here will match the shown route (even though it's being defined "wrongly" - Router::connect() calls aren't ment to be nested), so the problem is likely somewhere else, likely the same as in the linked question, but I'm not going to shoot in the dark further, so again, please show the stacktrace! - ndm

1 Answers

0
votes

The problem was in commented out HTML code which contains PHP code inside, code like this one:

<!-- <li role="presentation"><?= $this->Html->link(__('New Reservation'), ['controller' => 'Reservations', 'action' => 'add']) ?></li> -->

Which contains my old function without arguments add of Reservations Controller. I deleted any similar code and everything worked fine.