定制 dlpwd/router 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dlpwd/router

Composer 安装命令:

composer require dlpwd/router

包简介

Lightweight router library with named url parameters

关键字:

README 文档

README

Lightweight router library with named url parameters

Basic Usage

$router = new \dlpwd\router\Router();

$router->get('/', '\\dlpwd\\sample\\controller\\dashboard::renderDashboard');
$router->get('/login', '\\dlpwd\\sample\\controller\\login::showLoginForm');
$router->post('/login', '\\dlpwd\sample\\controller\\login::processLogin');
$router->get('/page/{friendlyUrl}', '\\dlpwd\\sample\\controller\\page::showPage');

$router->resolve();

Configuring Routes

The router supports three request methods, GET, POST and DELETE. There are corresponding methods in the router class to add routes for each request method

Router::get($_url, $_handler);
Router::post($_url, $_handler);
Router::delete($_url, $_handler);
Router::addRoute($_method, $_url, $_handler);

$_method

The request method can be specified when using the addRoute method on the router to create a new route. This method is useful when adding routes in bulk, for example after loading from a database or file, rather than using hard-coded routes.

$_url

The URL for the route should be specified with a leading forward-slash. Trailing forward-slashes are optional. The router will match requests with and without a trailing forward-slash to the same route. Parameters are specified within curly-braces. The name of the parameters must match the name of the parameters on the handler function, otherwise they will not be passed through

$_handler

The handler argument specifies the function to call if the route matches. The function can be specified in as any valid PHP callable

Resolving Routes

To have the router examine a URL and call the relevant controller, execute the resolve method. The resolve method will return any value returned by the controller function

Router::resolve($_url, $_method);

$_url

Omitting or passing null to the $_url parameter will cause the router to use the value of $_SERVER['REQUEST_URI']. Pass a url to this argument to manually run the router for a different URL than the one being requested

$_method

Omitting or passing null to the $_method parameter will cause the router to use the value of $_SERVER['REQUEST_METHOD']. Pass a method to this argument to override that value. Most useful when manually running the router with a different URL as above

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固