jinnguyen/puja-route
Composer 安装命令:
composer require jinnguyen/puja-route
包简介
Puja-Route is a router component, that allow to parse request to module/controller/action
README 文档
README
Puja-Route is a router component, that allow to parse request to module/controller/action
Install
composer require jinnguyen/puja-route
Usage
include /path/to/vendor/autoload.php; $config = array( 'root_namespace' => '\\Puja\\Route\\Demo\\', // You can change to match with controller class name on your app 'default_controller' => 'Index', // Default controller 'default_action' => 'index', // Default action 'controller_dir' => __DIR__ . '/Controller/', // Folder that includes controllers, controller must have prefix is Controller and file type is .php (Ex: UserController.php/IndexController.php, ...) 'module_dir' => __DIR__ . '/Module/', // Folder that includes app modules 'cache_dir' => __DIR__ . '/cache/', // Cache folder will store cached routers ); $router = new Puja\Route\Route($config); // when you build, it will scan all file *Controller.php in $config[controller_dir] and /Controller/*Controller.php in $config[module_dir]
Add more route
If your controller is not in $config[controller_dir] and $config[module_dir]//Controller/, you can also add it to route by this command:
$route->addRoute('/testaddroute', '\\Test\\Add\\Route\\Namespace');
Build
Scan all controller files and build routes from $config[controller_dir] and $config[module_dir] and controllers that was added by $router->addRoute()
$router->build();
Get route
Get router information: module, controller, action, ..
$router->getRoute('testaddroute') // get route at of testaddroute
Note:
- $router->getRoute() must run after $router->build() otherwise it will get exception
- Should call $router->build() after all $router->addRoute(), otherwise all added routes will be missed.
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache
- 更新时间: 2017-02-21