In the developer manual, there are several mentions about routes abbreviation. For example in notes tutorial section:
Now the controller methods need to be connected to the corresponding URLs in the notestutorial/appinfo/routes.php file:
<?php
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'note#index', 'url' => '/notes', 'verb' => 'GET'],
['name' => 'note#show', 'url' => '/notes/{id}', 'verb' => 'GET'],
['name' => 'note#create', 'url' => '/notes', 'verb' => 'POST'],
['name' => 'note#update', 'url' => '/notes/{id}', 'verb' => 'PUT'],
['name' => 'note#destroy', 'url' => '/notes/{id}', 'verb' => 'DELETE']
]
];
Since those 5 routes are so common, they can be abbreviated by adding a resource instead:
<?php
return [
'resources' => [
'note' => ['url' => '/notes']
],
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET']
]
];
My question is: isn’t there routing information loss? With the second codeblock, how does the server know, which controller method (in this case method update()) to use when user inserts request PUT with /notes/{id} in the URL?
In the first codeblock it’s clear → it just matches the url and the verb and uses route “note#update” (which corresponds to NoteController::update()).
But in the second codeblock, I don’t see how the server would know to call the same method with the same request.
Thanks.