alineisi/router

这个包用于实现具有许多酷炫功能的路由系统!!!

1.0 2022-04-28 10:12 UTC

This package is auto-updated.

Last update: 2024-09-16 11:23:14 UTC


README

PHP路由系统

需要PHP >= 7.0

安装

  • composer require alineisi/router

开始使用

  • require_once __DIR__ . '/vendor/autoload.php';
  • use Alineisi\Route;

确保添加

  • Route::dispatch();

到index.php的末尾

使用方法

示例1

  • Route::get('/', function () {
  • return 'Hello World';
  • });

示例2

  • Route::get('/', [HomeController::class, 'index']);

示例3

  • Route::post('/submit', function () {
  • return $_POST['name'];
  • });

功能

您可以使用

  • Route::notFoundPath($path);

在路由后使用name方法设置命名路由,例如

  • Route::get('/', function () {
  • return 'Hello World';
  • })->name('index');

然后使用它

  • \Alineisi\routeName('index');

您也可以通过使用

  • Route::view('/', 'index');

  • Route::view('/', 'index.php');