A PHP web framework that grouping routers by path
- Flight - An extensible micro-framework for PHP
-
RouteMap's index.php is like this
require 'vendor/autoload.php'; use RouteMap\Core\ApplicationFactory; $app = ApplicationFactory::create(); $app->router(); $app->start();
-
ApplicationFactory will create application by path-segment #1
if request url ishttps://domain_name/Index/var1/then create Index.php from
/ + /application + /Index.php -
In Index.php, method router is for routers setting
namespace Application; use Flight; use RouteMap\Core\Application; class Index extends Application { public function router() { Flight::route('/', function() { echo 'hello, world'; }); Flight::route('/var/@var', function($var){ echo 'get var = ' . $var; }); } }
-
request url
https://domain_name/Index/will see "hello, world"
request url
https://domain_name/Index/var/5will see "get var = 5"
-
RouteMap router features is use Flight router
more router features please see Flight - Routing
-
when you use Flight redirect method, your application(group) will automatically subjoin behind domain_name
-
if you want redirect to other application, you can use redirectOutside method that extension on Flight
-
class Index extends Application { public function router() { Flight::route('/', function() { Flight::redirect('/new/location'); }); ... } }
request /Index will redirect to /Index/new/location
class Index extends Application { public function router() { Flight::route('/', function() { Flight::redirectOutside('/new/location'); }); ... } }
request /Index will redirect to /new/location
-
redirectOutside just change the base url first, then call Flight::redirect
see more about redirect Flight - Redirect
-
RouteMap Config File location
/ + /config + /config.phpit return with php array format
-
RouteMap wrapper Flight config features by a Config Class
It will auto load RouteMap config file automatically
get it instance by getInstance ( it use Singleton Pattern )use RouteMap\Core\Config; $config = Config::getInstance();
-
RouteMap config features is a wrapper from Flight
it can also set config by array and object
see Flight - Variables
if you want use your own class in RouteMap, composer's autoload is setting already
...
"autoload": {
"psr-4": {
"RouteMap\\": "src/",
"Application\\": "application/",
"Extend\\": "extend/"
}
}
...just put them in /extend folder and load with Extend namespace
RouteMap is under the MIT license.
