mirror of https://gitee.com/topnuomi/framework
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace apps\home\controllers;
|
|
|
|
use top\base\Controller;
|
|
use top\base\Request;
|
|
use top\base\Response;
|
|
use top\base\response\Html;
|
|
use top\base\response\Json;
|
|
use top\base\response\Redirect;
|
|
use top\base\response\Text;
|
|
|
|
class News extends Controller
|
|
{
|
|
|
|
public function lists(Request $request, int $id, string $name, int $id1): Response
|
|
{
|
|
return $this->response(Json::class, [
|
|
'id' => $id,
|
|
'name' => $name,
|
|
'id1' => $id1,
|
|
]);
|
|
}
|
|
|
|
public function edit(int $id = 0): Response
|
|
{
|
|
return $this->response(Text::class, '编辑成功' . $id);
|
|
}
|
|
|
|
public function add(int $id): Response
|
|
{
|
|
return $this->response->setContent('测试123');
|
|
// return $this->response->setType(Redirect::class)->setContent('https://www.baidu.com');
|
|
// return $this->response->setType(Html::class)->setContent('<h2>测试</h2>');
|
|
// return $this->response(Redirect::class, 'https://www.baidu.com');
|
|
}
|
|
|
|
public function delete(int $id): Response
|
|
{
|
|
echo '执行到应用' . PHP_EOL;
|
|
return $this->response(Json::class, [
|
|
'msg' => '删除'
|
|
], 404);
|
|
}
|
|
|
|
private function response(string $type, $data, int $httpCode = 200): Response
|
|
{
|
|
return $this->response->setType($type)->setHttpCode($httpCode)->setContent($data);
|
|
}
|
|
|
|
}
|