一、在controller和model中
一、在controller和model中
1、 以下两个方法需要在控制器继承controller方法 use think\Controller; $this->success('操作成功!',url("index/index",['id'=>$id])); 设置成功后跳转页面的地址,默认的返回页面是$_SERVER[‘HTTP_REFERER’]。 $this->error('操作失败!',url("index/index",['id'=>$id])); 错误页面的默认跳转页面是返回前一页,通常不需要设置。 值得注意的是以上两个方法传递的参数get和post都接收不到,只能用input接收,或者是下面的方法: 首先调用Request函数方法 use think\Request; 然后使用Request函数接收值,$res 为接收到的所有值。 $request = Request::instance(); $res=$request->param(); 没有提示语直接跳转,用法和接收方法同上。 2、重定向方法: $this->redirect('index/index', ['id' => 2]);
二、在view中:
1、直接写 测试1//只写方法名,只能在本控制器中跳转 测试1//控制器名/方法名 测试1//模块名/控制器名/方法名 2、用TP自带的方法 测试1//只写方法名,只能在本控制器中跳转 测试1//控制器名/方法名 测试1//模块名/控制器名/方法名 以上两种方法可以用get接收值 3、类似于第二种 {:url(‘admin/index/index’,[‘id’=>1,‘name’=>‘admin’])} 接收方法: 只能用input接收,或者是下面的方法: 首先调用Request函数方法 use think\Request; 然后使用Request函数接收值,$res 为接收到的所有值。 $request = Request::instance(); $res=$request->param();
原文转载自:https://blog.csdn.net/qq_42455095/article/details/84561278
点个赞~