hexan45/router 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hexan45/router

最新稳定版本:v1.0.0

Composer 安装命令:

composer require hexan45/router

包简介

Easy to use and simply PHP router

README 文档

README

router library created with PHP language

Installation

Assuming you don't have initialized composer.json file. You must execute code given under below.

composer init
composer require hexan45/s-router:dev-main

In main project folder create .htaccess file and paste this code

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php?request=%{THE_REQUEST} [L]

To start using library create file named index.php in your root directory and use build in include() or require() function to include autoloading PSR-4 file named autoload.php.

Usage

In index.php file you must import router class by enter this code use Router/Route;

Create Route class instance

$Route = new Route();

Register path for GET uri method

$Route->Get(routePath: '/', routeController: callbackFunction());
or
$Route->Get(routePath: '/', routeController: [somethingControllerClass::class, 'somethingControllerMethod']);
or
$Route->Get(routePath: '/', routeController: 'somethingControllerClass@somethingControllerMethod');

Register path for POST uri method

$Route->Post(routePath: '/', routeController: callbackFunction());
or
$Route->Post(routePath: '/', routeController: [somethingControllerClass::class, 'somethingControllerMethod']);
or
$Route->Post(routePath: '/', routeController: 'somethingControllerClass@somethingControllerMethod');

Register dynamic routes

$Route->Post(routePath: '/article/$id', routeController: callbackFunction($id));
or
$Route->Post(routePath: '/some/$someID/thing/$thingID', routeController: callbackFunction($someID, $thingID));

Important thing! You must add the same names in callbackFunctions/methods parameters as in routePath.

Example

$Route->Post(routePath: '/article/$id', 'AdminController@index');

So in AdminController class, your index method should look like this

public function index($id) {...someCode}

Methods arguments

Get

  • routePath (string) - Path of uri which will be register in router
  • routeController (callable|array|string) - Code access details which specify code to run when user enter registered route path

Post

  • routePath (string) - Path of uri which will be register in router
  • routeController (callable|array|string) - Code access details which specify code to run when user enter registered route path

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固