First up, apologies for what already seems like a Kirby n00b Q! I have only just started playing with it.
I am exploring alternate methods for building a sensible api with kirby to work with either Angular 1 or ReactJs…
I have managed to build a very basic api using invisible routes no problem, but now want to be able to use the built in routes options…
From the docs:
http://getkirby.com/docs/advanced/routing
c::set('routes', array(
array(
'pattern' => 'my/awesome/url',
'action' => function() {
// do something here when the URL matches the pattern above
}
)
));
When i drop this snippet of code into the main site config file I cannot get the route to match… here is my snippet:
/**
* Custom routing
*/
c::set('routes', array(
array(
'pattern' => 'john/(:any)/(:num)/(:all)',
'action' => function( $anyPlaceholder, $numPlaceholder, $allPlaceholder ) {
// do something here when the URL matches the pattern above
/*print_r( $anyPlaceholder );
print_r( $numPlaceholder );
print_r( $allPlaceholder );*/
die('x');
/*return response::json(array(
'some', 'json', 'stuff'
));*/
},
'method' => 'GET|POST|DELETE'
)
));
You would expect the route to be hit and and x printed to screen. However I can only get the error page.
Is there more to registering new routes than simply dropping them into the ‘site/config/config.php’ file?
Cheers,
John