close
Phork Manual Table of Contents
Phork Framework User Guide 1.3.4

Routing

The standard routing uses the parsed URL data in the CoreUrl object to determine the controller to use from the first URL segment and the method in that controller from the second segment.

For example if the URL were http://www.example.org/foo/bar/ then the controller would be FooController and the method would be displayBar(). If there is no second segment then the displayIndex() method is called. If there are no segments at all then the default controller defined in the boostrap is used with the displayIndex() method.

Routing allows you to re-route a URL to use a controller and method that break from this standard. The routing overrides are set in the site configuration file.

Routing rules can use regular expressions and backreferences (eg. $1) are automatically replaced.


Example

//route http://www.example.org/foo/bar/ to DemoController and displayBaz()
$arrConfig['Routes']['^/foo/bar/$'] = '/demo/baz/';

//route http://www.example.org/foo/[segment]/ to DemoController display[Segment]
$arrConfig['Routes']['^/foo/([^/]+)/$'] = '/demo/$1/';

//route the index to SiteController displaySplash()
$arrConfig['Routes']['^/?$'] = '/site/splash/';