Skip to content

Commit

Permalink
Allow to use snippet as handler
Browse files Browse the repository at this point in the history
  • Loading branch information
vanchelo committed Apr 19, 2015
1 parent ec8dc2c commit c7e1650
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
["GET","/fastrouter/{name}/{id:[0-9]+}","1"],
["GET","/fastrouter/{id:[0-9]+}","1"],
["GET","/hello/{name}","1"],
["GET","/some_snippet/{id}","fastrouter"],
["GET","/contact","1"]
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$key = $modx->getOption('fastrouter.paramsKey', null, 'fastrouter');
$params = isset($_REQUEST[$key]) ? $_REQUEST[$key] : array();
$params = $modx->getOption($key, $scriptProperties, isset($_REQUEST[$key]) ? $_REQUEST[$key] : array());

return '<pre>' . print_r($params, true) . '</pre>';
22 changes: 14 additions & 8 deletions core/components/fastrouter/fastrouter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,29 @@ public function dispatch() {
return $this->handle($params[1], $params[2]);
break;
}

return null;
}

/**
* @param mixed $route_handler
* @param mixed $routeHandler
* @param array $data
*
* @return null
*/
protected function handle($route_handler, array $data)
{
$_REQUEST += array($this->paramsKey => $data);

if (is_numeric($route_handler)) {
$this->modx->sendForward($route_handler);
protected function handle($routeHandler, array $data) {
if (is_numeric($routeHandler)) {
// Send forward to resource
$_REQUEST += array($this->paramsKey => $data);
$this->modx->sendForward($routeHandler);
} else {
echo $this->modx->runSnippet($route_handler);
// Call snippet
echo $this->modx->runSnippet($routeHandler, array(
$this->paramsKey => $data
));
die;
}

return null;
}

Expand Down
1 change: 1 addition & 0 deletions core/components/fastrouter/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
$r->addRoute('GET', '/fastrouter/{name}/{id:[0-9]+}', '1');
$r->addRoute('GET', '/fastrouter/{id:[0-9]+}', '1');
$r->addRoute('GET', '/hello/{name}', '1');
$r->addRoute('GET', '/some_snipper', 'snippet_name');

0 comments on commit c7e1650

Please sign in to comment.