zoukankan      html  css  js  c++  java
  • yii2.0里的redirect跳转方法

     

    在yii2框架里难免会出现跨控制器跳转,调用方法等,这就用到了redirect了,

     

    带参数的

     

    $control=Yii::app()->runController('site/show/id/2');

     

    不带参数的

     

    $control=Yii::app()->runController('site/show');

     

    redirect使用方法:

     

    一般都是控制器层里执行某段代码结束之后跳转到其他控制器的方法里,

     

    $this->redirect(array('/site/contact','id'=>12));     //相当于跳到http://www.11111.com/testwebap/index.php?r=site/contact & id=12

     

    $this->redirect(array('site/contact','id'=>'idv','name'=>'namev'));  //带参数?r=site/contact & id=idv & name=namev

     

    $this->redirect(array('site/contact','v1','v2','v3'));   //?r=site/contact & 0=v1 & 1=v2 & 2=v3

     

    $this->redirect(array('site/contact','v1','v2','v3','#'=>'ttt'));   //带anchor的 ?r=site/contact & 0=v1 & 1=v2 & 2=v3#ttt

     

    跳转到绝对路径:

     

    $this->redirect('http://www.baidu.com');

     

  • 相关阅读:
    TechRoad_oneStep_0410
    Tech road one step
    TechRoad--oneStep--0327
    TechRoad_oneStep 0313
    Tech road one step
    Tech road one step
    Tech road one step
    Tech road one step
    Tech road one step
    Tech road one step
  • 原文地址:https://www.cnblogs.com/iceman-/p/8492385.html
Copyright © 2011-2022 走看看