承接 sw04/route-me 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sw04/route-me

最新稳定版本:v1

Composer 安装命令:

composer require sw04/route-me

包简介

router with routes groups & before-after actions

README 文档

README

Light php routing library support:

  • routes
  • optional & requirements params
  • group routes
  • actions before & after route
  • define controller, method & params

Composer install:

composer require sw04/route-me

Initialize:

$router = \Router\Singleton::getInstance();

Simple route for GET and POST methods with required integer and string param:

$router->get('/show/{[0-9]+}'); //sample: GET /show/1024
$router->post('/show/{[a-z]+}'); //sample: POST /show/sample

Simple route with not required param:

$router->get('/show/!{[0-9]+}'); //sample: GET /show or /show/1024

Simple route with defined controller & method:

$router
    ->setController('index')
    ->setMethod('index')
    ->get('/')
    ->clear();

Simple group routes(set prefix "/admin") and add actions before route match:

function isAuth() {
    //check auth & return true or false
    return true;
}
function isAdmin() {
    //check role is admin or not & return true or false
    return false;
}
$router
    ->setPrefix('/admin')
    ->setAction('before', 'isAuth')
    ->setAction('before', 'isAdmin')
    ->get('/dashboard')
    ->clear();

Simple set prefix(namespace) for all classes:

$router->setNamespace('\\Application\\Project\\');

Match routes:

try {
    $result = $router->match(getenv('REQUEST_URI'));
    if (is_array($result)) { //convert to json if is array
        $result = json_encode($result);
    }
    echo $result; //echo result of match
} catch(\Router\RouterException $e) {
    echo $e->getMessage().' code is '.$e->getCode();
}

All routes set next requirements for routes:

method - GET, POST, ANY
prefix - for route url
url - to route
actions - before & after route match
defineClass - define controller
defineMethod - define method
defineParams - define params

For clear all this requirements use:

$routes->clear();

统计信息

  • 总下载量: 45
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2014-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固