php中的jump(),thinkphp-jump

软件简介

thinkphp-jump

适用于thinkphp6.0的跳转扩展

安装

composer require liliuwei/thinkphp-jump

配置

// 安装之后会在config目录里生成jump.php配置文件

return[

// 默认跳转页面对应的模板文件

'dispatch_success_tmpl' => app()->getRootPath().'/vendor/liliuwei/thinkphp-jump/src/tpl/dispatch_jump.tpl',

'dispatch_error_tmpl' => app()->getRootPath().'/vendor/liliuwei/thinkphp-jump/src/tpl/dispatch_jump.tpl',

];

用法示例

使用 use \liliuwei\think\Jump;

在所需控制器内引用该扩展即可:

namespace app\admin\controller;

class Index

{

use \liliuwei\think\Jump;

public function demo1()

{

/**

* 操作成功跳转的快捷方法

* @param mixed $msg 提示信息

* @param string $url 跳转的URL地址

* @param mixed $data 返回的数据

* @param integer $wait 跳转等待时间

* @param array $header 发送的Header信息

*/

// 一般用法

return $this->success('登录成功', 'index/index');

//完整用法

//return $this->success($msg = '登录成功', $url = 'index/index', $data = '', $wait = 3, $header = []);

}

public function demo2()

{

/**

* 操作错误跳转的快捷方法

* @param mixed $msg 提示信息

* @param string $url 跳转的URL地址

* @param mixed $data 返回的数据

* @param integer $wait 跳转等待时间

* @param array $header 发送的Header信息

*/

// 一般用法

return $this->error('登录失败');

//return $this->success('登录失败','login/index');

//完整用法

//return $this->error($msg = '登录失败', $url = 'login/index', $data = '', $wait = 3, $header = []);

}

public function demo3()

{

/**

* URL重定向

* @param string $url 跳转的URL表达式

* @param integer $code http code

* @param array $with 隐式传参

*/

//一般用法

//第一种方式:直接使用完整地址(/打头)

//return $this->redirect('/admin/index/index');

//第二种方式:如果你需要自动生成URL地址,应该在调用之前调用url函数先生成最终的URL地址。

return $this->redirect(url('index/index', ['name' => 'think']));

//return $this->redirect('http://www.thinkphp.cn');

//完整用法

//return $this->redirect($url= '/admin/index/index', $code = 302, $with = ['data' => 'hello']);

}

public function demo4()

{

/**

* 返回封装后的API数据到客户端

* @param mixed $data 要返回的数据

* @param integer $code 返回的code

* @param mixed $msg 提示信息

* @param string $type 返回数据格式

* @param array $header 发送的Header信息

*/

//一般用法

return $this->result(['username' => 'liliuwei', 'sex' => '男']);

//完整用法

//return $this->result($data=['username' => 'liliuwei', 'sex' => '男'], $code = 0, $msg = '', $type = '', $header = []);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值