[BUG] Micro collections not returning Router
Hi Folks
I am writing some custom collections for my routes so I can seperate them into reasonable groups under a controller, and I have found a bug in the software.
The documentation states that the collection's get, put, post and delete methods will return an object implementing the Phalcon\Mvc\Router\RouteInterface interface, however after doing the following code the methods return null (or void).
$collection->setHandler('Controller\Entity\Customer', true);
$getReturn = $collection->get('/customer/{id}', 'get');
$putReturn = $collection->put('/customer/{id}', 'put');
$deleteReturn = $collection->delete('/customer/{id}', 'delete');
$postReturn = $collection->post('/customer', 'post');
var_dump($getReturn, $putReturn, $deleteReturn, $postReturn);
This then returns:
NULL
NULL
NULL
NULL
Discovered this while trying to use the setName() method on the return of these route aditions.
I think it is wrong document.
Hi Dreamsxin what do you mean by wrong document?
What I mean is that it should not return values. I view the Phalcon\Mvc\Micro\Collection source code, Did not return to the operating, And get\put\delete\post These methods do not require the second argument.
This is a bug. It is not really a problem if your are using get,put,delete, and post method, but it become a problem when using map. If the map can return Router interface, it can be called as $collection->map(...)->via(['POST','PUT']);
I have reported similiar BUG in: https://github.com/phalcon/cphalcon/issues/1037
Any chance anyone can look at this?
This is the bug in the documentation — the methods should return Phalcon\Mvc\Micro\CollectionInterface, not Phalcon\Mvc\Router\RouteInterface
This is fixed in 1.2.4/1.3.0