Permalink
Browse files

Added possibility to have optional parts in route

  • Loading branch information...
1 parent d2aabd1 commit 999b28c3fb196d7e6d8a149b5a3cfc80347eef87 Vincent committed Jul 3, 2009
Showing with 6 additions and 11 deletions.
  1. +1 −0 active-php/controller.php
  2. +5 −11 www/wiki.php
@@ -159,6 +159,7 @@ class ActiveController
/*static*/ function _tryExtractParams($pathInfo, $currentPathInfo)
{
$pathInfo = preg_replace('$([.\+*?()[/\\]])$', '\\\\\\1', $pathInfo);
+ $pathInfo = preg_replace('$\\\\\\((.+?)\\\\\\)$', '(\\1)?', $pathInfo);
$pathInfo = preg_replace('$:([a-z]+)$', '(?P<\\1>.+?)', $pathInfo);
$pathInfo = '/^'.$pathInfo.'$/';
View
@@ -12,8 +12,7 @@ function authenticate($user, $password)
}
///////////////////////////////////////////////////////////////////////////////
-ActiveController::route('get', 'pages.:format', 'getPageList');
-ActiveController::route('get', 'pages', 'getPageList');
+ActiveController::route('get', 'pages(.:format)', 'getPageList');
function getPageList($params)
{
@@ -27,18 +26,15 @@ function getPageList($params)
}
///////////////////////////////////////////////////////////////////////////////
-ActiveController::route('post', 'pages.:format', 'getPageList');
-ActiveController::route('post', 'pages', 'createPage');
+ActiveController::route('post', 'pages(.:format)', 'getPageList');
function createPage($params)
{
}
///////////////////////////////////////////////////////////////////////////////
-ActiveController::route('get', 'pages/:id.:format', 'getPage');
-ActiveController::route('get', 'pages/:id', 'getPage');
-
+ActiveController::route('get', 'pages/:id(.:format)', 'getPage');
function getPage($params)
{
if( $params['id'] == 'Plop' )
@@ -62,17 +58,15 @@ function getPageAsHtml($params)
}
///////////////////////////////////////////////////////////////////////////////
-ActiveController::route('put', 'pages/:id.:format', 'updatePage');
-ActiveController::route('put', 'pages/:id', 'updatePage');
+ActiveController::route('put', 'pages/:id(.:format)', 'updatePage');
function updatePage($params)
{
echo 'updatePage';
}
///////////////////////////////////////////////////////////////////////////////
-ActiveController::route('delete', 'pages/:id.:format', 'deletePage');
-ActiveController::route('delete', 'pages/:id', 'deletePage');
+ActiveController::route('delete', 'pages/:id(.:format)', 'deletePage');
function deletePage($params)
{

0 comments on commit 999b28c

Please sign in to comment.