Joel Hernandez
Joel Hernandez

Reputation: 1897

Micro Collection of Routes with handler not matched

What I am trying to accomplish is the following

$collection = new Phalcon\Mvc\Micro();
$collection->setHandler(new \app\Controllers\Brands());
$collection->setPrefix('api/brands');
$collection->get('','actionIndex');
$collection->post('/search','actionSearch');
$collection->get('/{id:[0-9]+}','resourceGet');
$collection->put('/{id:[0-9]+}','resourcePut');
$collection->delete('/{id:[0-9]+}','resourceDelete');

$app->mount($collection);

However no route is matched when going through it's URI as www.domain.com/api/brands/search, but the odd thing here is that the app itself can handle the routes if specified on the script as

$app->handle('api/brands/search');

A quick and dirty fix for this would be the following

$app->handle(substr($_GET['_url'], 1));

but I would like to know if there's a better way to solve it.

Any suggestion or answer is highly appreciated! Thank you!

Upvotes: 0

Views: 1509

Answers (1)

Ian Bytchek
Ian Bytchek

Reputation: 9075

Make sure you set the base uri and make sure your routes start with '/'. That's the most common problem. Since you are using micro, I guess you don't need to worry about setBaseUri() because it's not used in your app.

$di->set('url', function(){
    $url = new Phalcon\Mvc\Url();
    $url->setBaseUri('/');
    return $url;
});

$collection->setPrefix('/api/brands');

Upvotes: 1

Related Questions