TP5的页面跳转与重定向

1、页面跳转的目标有哪些?

调用方法:

$this->success('提示','地址');
$this->error('提示','地址');

index.php文件内容:

<?php
namespace app\index\controller;
class Index extends \think\Controller
{
  public function index()
  {
    return '<h2>欢迎来到PHP中文网学习ThinkPHP5开发技术</h2>';
  }
  public function hello($name)
  {
    if($name == 'thinkphp')
    {
      $this->success('验证成功,正在跳转~~~','ok');
    } else {
      $this->error('验证失败,正在返回登陆界面……','login');
    }
  }
  public function ok()
  {
    return '欢迎使用后台管理系统';
  }
  public function login()
  {
    return '登陆页面';
   }
}
?>

跳转地址这样写也是可以的:

$this->success('验证成功,正在跳转~~~',\think\Url::build('demo/login/ok'));

$this->success('验证成功,正在跳转~~~',\think\Url::build('https://www.bilibili.com/'));

$this->success('验证成功,正在跳转~~~',url('https://www.bilibili.com/'); //url是助手函数,功能同上

2、如何设置URL访问的重定向?

调用方法:

$this->redirect('路由地址',[变量列表],'后缀','域名开关');

index.php文件内容:

<?php
namespace app\index\controller;
class Index extends \think\Controller
{
  public function index()
  {
    return '<h2>欢迎来到PHP中文网学习ThinkPHP5开发技术</h2>';
  }
  public function hello($name)
  {
    if($name == 'thinkphp')
    {
/*******************以下是变化*******************/
      $this->redirect('ok',['siteName'=>'php中文网']);
    } else {
      $this->redirect('http://www.php.cn',302); //302是临时重定向,301是永久重定向
    }
  }
  public function ok($siteName)
  {
    return '欢迎来到'.$siteName.'学习ThinkPHP5开发技术';
  }
  public function login()
  {
    return '登陆页面';
   }
}
?>


作者:傲娇的泰迪
链接:https://www.jianshu.com/p/9b9d9d68e1aa
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值