1. Go to this page and download the library: Download duxweb/dux-lite 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/ */
duxweb / dux-lite example snippets
// app/Web/App.php - Web 模块注册类
namespace App\Web;
use Core\App\AppExtend;
use Core\Bootstrap;
class App extends AppExtend
{
public function init(Bootstrap $bootstrap): void
{
// 模块初始化逻辑
}
public function register(Bootstrap $bootstrap): void
{
// 注册服务和组件
}
public function boot(Bootstrap $bootstrap): void
{
// 模块启动逻辑
}
}
// 传统路由定义
use Core\App;
App::route()->get('/users', [UserController::class, 'index']);
App::route()->post('/users', [UserController::class, 'store']);
App::route()->get('/users/{id}', [UserController::class, 'show']);
// 属性注解路由
#[Route('/api/users', methods: ['GET'])]
#[Route('/api/users', methods: ['POST'], name: 'users.store')]
class UserController
{
public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$users = User::paginate(15);
return response()->json($users);
}
public function store(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$data = $request->getParsedBody();
$user = User::create($data);
return response()->json($user, 201);
}
}