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?
<?= $this->Html->link(__('Reservation'), ['controller' => 'Reservations','action' => 'add', $car->id]) ?>
- Br.sasareservations/add($carid)
is NOT being called from the current controllerreservations
,but fromcars
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 routeRouter::connect('/rentcar/:id', ['controller' => 'Reservations', 'action' => 'add'],['pass' => ['id'], 'id' => '[0-9]+']);
- Br.sasaRouter::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