{"action":"created","issue":{"url":"https://api.github.com/repos/dannyvankooten/AltoRouter/issues/144","repository_url":"https://api.github.com/repos/dannyvankooten/AltoRouter","labels_url":"https://api.github.com/repos/dannyvankooten/AltoRouter/issues/144/labels{/name}","comments_url":"https://api.github.com/repos/dannyvankooten/AltoRouter/issues/144/comments","events_url":"https://api.github.com/repos/dannyvankooten/AltoRouter/issues/144/events","html_url":"https://github.com/dannyvankooten/AltoRouter/issues/144","id":146012097,"number":144,"title":"Call class and method and pass parameters using global route","user":{"login":"iamdriz","id":801252,"avatar_url":"https://avatars.githubusercontent.com/u/801252?v=3","gravatar_id":"","url":"https://api.github.com/users/iamdriz","html_url":"https://github.com/iamdriz","followers_url":"https://api.github.com/users/iamdriz/followers","following_url":"https://api.github.com/users/iamdriz/following{/other_user}","gists_url":"https://api.github.com/users/iamdriz/gists{/gist_id}","starred_url":"https://api.github.com/users/iamdriz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamdriz/subscriptions","organizations_url":"https://api.github.com/users/iamdriz/orgs","repos_url":"https://api.github.com/users/iamdriz/repos","events_url":"https://api.github.com/users/iamdriz/events{/privacy}","received_events_url":"https://api.github.com/users/iamdriz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-05T14:47:35Z","updated_at":"2016-04-05T22:27:45Z","closed_at":null,"body":"Is it possible to create a global route that will call a class and method and pass any optional parameters (including query strings)?\r\n\r\nSo for example let's say I have the following class acting as a controller and containing methods for actions (like in an MVC pattern). I also want to catch if the action isn't passed and default to the Index method in the controller.\r\n\r\n~~~\r\nclass App\r\n{\r\n\tpublic static function Index()\r\n\t{\r\n\t\techo 'Index!';\r\n\t\tif(isset($_REQUEST['page'])) echo 'Page: ' . $_REQUEST['page'];\r\n\t}\r\n\t\r\n\tpublic static function Create()\r\n\t{\r\n\t\techo 'Create!';\r\n\t}\r\n\t\r\n\tpublic static function Edit($id)\r\n\t{\r\n\t\techo 'Edit! '.$id;\r\n\t}\r\n\t\r\n\tpublic static function Delete($id)\r\n\t{\r\n\t\techo 'Delete! '.$id;\r\n\t}\r\n\t\r\n\tpublic static function View($id)\r\n\t{\r\n\t\techo 'View! '.$id;\r\n\t}\r\n}\r\n~~~\r\n\r\nThen I want the following URLs to all be catch able and hook up to the above class methods:\r\n\r\n~~~\r\nlocalhost/Demo/LearnBuddy/v1/App/\r\nlocalhost/Demo/LearnBuddy/v1/App/?page=2\r\nlocalhost/Demo/LearnBuddy/v1/App/Index/\r\nlocalhost/Demo/LearnBuddy/v1/App/Index/?page=2\r\nlocalhost/Demo/LearnBuddy/v1/App/Create/\r\nlocalhost/Demo/LearnBuddy/v1/App/Edit/22/\r\nlocalhost/Demo/LearnBuddy/v1/App/Delete/22/\r\nlocalhost/Demo/LearnBuddy/v1/App/View/22/\r\nlocalhost/Demo/LearnBuddy/v1/App/View/22/\r\n~~~\r\n\r\nUsing something along the lines of:\r\n\r\n~~~\r\n$router = new AltoRouter();\r\n\r\n$router->setBasePath(\"C:\\_Dev\\LearnBuddy\\v1\\\");\r\n\r\n// home\r\n$router->map( 'GET', '/', function() {\t\r\n\techo 'home';\r\n});\r\n\r\n// call the index if no action is passed\r\n$router->map( 'GET', '/[a:controller]/', function( $controller ) {\t\r\n\tif( method_exists( $controller, $action ) )\r\n\t\t$controller::Index();\r\n\telse\r\n\t\techo 'missing';\r\n});\r\n\r\n// call controller and action and pass any parameters\r\n$router->map( 'GET', '/[a:controller]/[a:action]/[a:params]', function( $controller, $action, $params ) {\r\n\tif( method_exists( $controller, $action ) )\r\n\t\t$controller::$action($params);\r\n\telse\r\n\t\techo 'missing';\r\n});\r\n\r\n$match = $router->match();\r\n\r\nvar_dump($match);\r\n\r\n// call closure or throw error\r\nif( $match && is_callable( $match['target'] ) )\r\n{\r\n\tcall_user_func_array( $match['target'], $match['params'] ); \r\n}\r\nelse\r\n{\r\n\techo 'error';\r\n}\r\n~~~\r\n\r\nSo in short, how can I amend the above code to catch controller and action with optional params and query strings? Currently I'm just getting `bool(false)` when I `var_dump($match);`.\r\n\r\nThis is on a Windows machine running IIS (the web config seems to fine, as all URLs are hitting the index.php file so I don't think that is causing none of them to work.)."},"comment":{"url":"https://api.github.com/repos/dannyvankooten/AltoRouter/issues/comments/206012298","html_url":"https://github.com/dannyvankooten/AltoRouter/issues/144#issuecomment-206012298","issue_url":"https://api.github.com/repos/dannyvankooten/AltoRouter/issues/144","id":206012298,"user":{"login":"irecinius","id":4451694,"avatar_url":"https://avatars.githubusercontent.com/u/4451694?v=3","gravatar_id":"","url":"https://api.github.com/users/irecinius","html_url":"https://github.com/irecinius","followers_url":"https://api.github.com/users/irecinius/followers","following_url":"https://api.github.com/users/irecinius/following{/other_user}","gists_url":"https://api.github.com/users/irecinius/gists{/gist_id}","starred_url":"https://api.github.com/users/irecinius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/irecinius/subscriptions","organizations_url":"https://api.github.com/users/irecinius/orgs","repos_url":"https://api.github.com/users/irecinius/repos","events_url":"https://api.github.com/users/irecinius/events{/privacy}","received_events_url":"https://api.github.com/users/irecinius/received_events","type":"User","site_admin":false},"created_at":"2016-04-05T22:27:45Z","updated_at":"2016-04-05T22:27:45Z","body":"BasePath is wrong, thats why its not hitting any match"}}