rahat1470/php-router

在您的应用程序中创建美观且干净的路由系统

3.1 2024-05-22 05:10 UTC

This package is auto-updated.

Last update: 2024-09-22 05:50:08 UTC


README

在php路由器中基本使用

  1. 使用以下命令安装php路由器:composer require rahat1470/php-router

  2. 在您的项目根目录中创建一个 .htaccess 文件,并写下以下代码。

    RewriteEngine On
    RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.webp|\.gif|\.jpeg|\.zip|\.css|\.svg|\.js|\.pdf)$
    RewriteRule (.*) index.php [QSA,L]
    
    
  3. 在您的应用程序中创建第一个路由。

    use Rahat1470\PhpRouter\Route;
    
    Route::get('/',function(){
        return 'Hello World';
    });
    
    // or
    
    Route::get('/',[App::class, 'method']);
    
    
  4. 您可以传递一些参数,例如

    use Rahat1470\PhpRouter\Route;
    
    Route::get('/posts/$post_name',function($post_name){
        return $post_name;
    });
    
    
  5. 您可以通过传递动态参数访问您的类

    use Rahat1470\PhpRouter\Route;
    
    Route::get('/posts/$post_url',[Post::class, 'findPost']);
    
    // Post Class
    class Post{
        public static function findPost($url){
            return $url;
        }
    }