1. Go to this page and download the library: Download loner/http-route library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
# Resource 模式
declare(strict_types=1);
namespace App\Controller;
use Loner\Http\Route\Attribute\Resource;
// #[Resource] 同 $tap->prefix('users');
// #[Resource(2)] 同 $tap->prefix('controller/users');
// #[Resource(3)] 同 $tap->prefix('app/controller/users');
// #[Resource('abc')] 同 $tap->prefix('abc');
#[Resource]
class Users
{
// 同 Route::get('', Users::class . '::index')->prefix('users');
public function index()
{
return '用户列表页面'
}
// 同 Route::get('create', Users::class . '::create')->prefix('users');
public function create()
{
return '创建用户页面';
}
// 同 Route::post('', Users::class . '::store')->prefix('users');
public function store()
{
return '创建用户提交';
}
// 同 Route::get('{id}', Users::class . '::show')->prefix('users');
public function show(int $id)
{
return sprintf('ID 为 %d 的用户详情页', $id);
}
// 同 Route::get('{id}/edit', Users::class . '::edit')->prefix('users');
public function edit(int $id)
{
return sprintf('ID 为 %d 的用户修改页', $id);
}
// 同 Route::many(['PUT', 'PATCH'], '{id}', Users::class . '::update')->prefix('users');
public function update(int $id)
{
return sprintf('ID 为 %d 的用户修改提交', $id);
}
// 同 Route::delete('{id}', Users::class . '::destroy')->prefix('users');
public function destroy(int $id)
{
return sprintf('ID 为 %d 的用户删除提交', $id);
}
}
use App\Controller\{Demo, Users};
use Loner\Http\Route\Router;
Router::load(new ReflectionClass(Demo::class));
Router::load(new ReflectionClass(Users::class));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.