HTTP控制器中,如果需要实现重定向功能,我们就必须依赖Swoole的Response对象,为了方便使用,x\controller\Http
基类本身就提供了redirect()
方法便捷使用。
依赖类:\x\controller\Http
方法名:redirect()
参数:
string $url
int $status
302
array $data
[]
返回值:bool
namespace app\http;
// 控制器系统基类
use x\controller\Http;
class Index extends Http
{
/**
* @RequestMapping(route="/", method="get", title="我是路由定义注解")
*/
public function index() {
// 直接跳转到:当前域名/index/test路由后缀 的URL
return $this->redirect('index/test', 301);
// 带get参数跳转
// 直接跳转到:当前域名/index/test路由后缀?id=1 的URL
return $this->redirect('index/test', 301, ['id' => 1]);
// 直接用第三方域名跳转
return $this->redirect('http://sw-x.cn', 301);
}
}