0

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!

Joel Hernandez
  • 1,817
  • 4
  • 18
  • 27

1 Answers1

1

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');
Ian Bytchek
  • 8,804
  • 6
  • 46
  • 72
  • 1
    I can't believe I've been going around this thing for so long... I even wrote tests for the freaking router class... Thank you Ian.. – Joel Hernandez Sep 04 '14 at 05:18
  • 1
    I know man, Phalcon is a pain to debug, but hey – there's an opportunity to learn C by example :) – Ian Bytchek Sep 04 '14 at 09:18