init
This commit is contained in:
97
code/app/home/BaseController.php
Normal file
97
code/app/home/BaseController.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\home;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\View;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
|
||||
// View::assign('')
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, string|array $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
[$validate, $scene] = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
|
||||
return $v->failException(true)->check($data);
|
||||
}
|
||||
|
||||
}
|
||||
5
code/app/home/config/view.php
Normal file
5
code/app/home/config/view.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use app\model\AutoSwitchViewModel;
|
||||
|
||||
return AutoSwitchViewModel::getViewConfig();
|
||||
@@ -1,17 +1,37 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
class Index
|
||||
use app\home\BaseController;
|
||||
use storage\StorageCore;
|
||||
use think\facade\View;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$arrConfig = config();
|
||||
echo '<pre>';
|
||||
print_r($arrConfig);
|
||||
echo '</pre>';
|
||||
// exit;
|
||||
return '您好!这是一个[home]示例应用';
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
|
||||
$strNovelKey = "novels/12/chapters/3001.txt";
|
||||
$StorageCore = StorageCore::getInstance();
|
||||
|
||||
// $content = '我是一个大傻逼';
|
||||
|
||||
$content = file_get_contents('123.txt');
|
||||
|
||||
if ($StorageCore->has($strNovelKey)) {
|
||||
// $MinIO->update($strNovelKey, $content); // 更新已有文件
|
||||
} else {
|
||||
$StorageCore->write($strNovelKey, $content); // 创建新文件
|
||||
}
|
||||
|
||||
echo $StorageCore->read($strNovelKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
17
code/app/home/controller/Novel.php
Normal file
17
code/app/home/controller/Novel.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
use app\home\BaseController;
|
||||
use storage\StorageCore;
|
||||
use think\facade\View;
|
||||
|
||||
class Novel extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
1
code/app/home/view/default/Index/index.html
Normal file
1
code/app/home/view/default/Index/index.html
Normal file
@@ -0,0 +1 @@
|
||||
12312321
|
||||
1
code/app/home/view/default/Novel/index.html
Normal file
1
code/app/home/view/default/Novel/index.html
Normal file
@@ -0,0 +1 @@
|
||||
12312321
|
||||
Reference in New Issue
Block a user