mouyong / webman-init-template
There is no license information available for the latest version (dev-master) of this package.
dev-master
2022-03-17 16:07 UTC
Requires
- illuminate/database: ^8.0 || ^9.5
- illuminate/events: ^8.0 || ^9.5
- illuminate/pagination: ^8.0 || ^9.5
- mouyong/validate: ^1.0
- robmorgan/phinx: ^0.12.10
- vlucas/phpdotenv: ^5.4
- webman/console: ^1.0
- yzh52521/webman-event: ^1.0
- zhenmu/support: ^1.0
This package is auto-updated.
Last update: 2024-12-17 22:28:31 UTC
README
注意: 安装包之前,先移除项目的 composer.lock 文件,避免无法安装 phinx 包的问题 (https://www.workerman.net/q/8016)
rm composer.lock && composer require mouyong/webman-init-template:dev-master
启用插件
./webman plugin:install zhen-mu/support
./webman plugin:install mouyong/validate
./webman plugin:install mouyong/webman-init-template
rm app/controller/WebmanBaseController.php
引入的第三方包
使用
- 禁用默认路由,并按照文档配置路由信息 https://www.workerman.net/doc/webman/route.html
config/route.php
Route::disableDefaultRoute();
config/database.php
return [
// 默认数据库
'default' => 'mysql',
// 各种数据库配置
'connections' => [
'mysql' => [
'driver' => getenv('DB_DRIVER') ?: 'mysql',
'host' => getenv('DB_HOST') ?: '127.0.0.1',
'port' => getenv('DB_PORT') ?: 3306,
'database' => getenv('DB_DATABASE') ?: 'webman',
'username' => getenv('DB_USERNAME') ?: 'root',
'password' => getenv('DB_PASSWORD') ?: '',
'unix_socket' => getenv('DB_UNIX_SOCKET') ?: '',
'charset' => getenv('DB_CHARSET') ?: 'utf8mb4',
'collation' => getenv('DB_COLLATION') ?: 'utf8mb4_bin',
'prefix' => getenv('DB_PREFIX') ?: '',
'strict' => getenv('DB_STRICT') ?: true,
'engine' => getenv('DB_ENGINE') ?: null,
],
],
];
- 在项目目录下创建 .env 文件,并更具需要配置环境变量
cp .env.example .env
# database
DB_DRIVER=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=webman
DB_USERNAME=root
DB_PASSWORD=root
- 控制器继承
<?php
namespace app\controller;
use support\Request;
use Mouyong\WebmanInitTemplate\Controllers\WebmanBaseController;
class Index extends WebmanBaseController
{
<...>
}
- 错误处理集成
见文档 README.md 说明: https://github.com/mouyong/php-support
support/exception/Handle.php
<?php
namespace support\exception;
use Webman\Http\Request;
use Webman\Http\Response;
use Throwable;
use Webman\Exception\ExceptionHandler;
use ZhenMu\Support\Traits\WebmanResponseTrait;
class Handler extends ExceptionHandler
{
use WebmanResponseTrait;
<...>
public function render(Request $request, Throwable $exception): Response
{
return $this->renderableHandle($request, $exception); // 这里进行调用,做了一些错误捕捉
}
}