Cake PHP redirect with parameters in url

前端 未结 4 1472
挽巷
挽巷 2020-12-24 11:57

I have a page that I want to redirect to that requires parameters in the URL: http://www.example.com/myController/myAction/param1:val1/param2:val2

I know that there

相关标签:
4条回答
  • 2020-12-24 12:34

    I usually do something like this:$this->redirect(['action' => 'view', $id, 'admins' => true]);

    Hope it will help you.

    0 讨论(0)
  • 2020-12-24 12:38

    If you need to redirect with exactly get parameters, then pass '?' index to $url array argument:

    $this->redirect(
        array(
              "controller" => "myController", 
              "action" => "myAction",
              "?" => array(
                  "param1" => "val1",
                  "param2" => "val2"
              ),
              $data_can_be_passed_here
        ),
        $status,
        $exit
    );
    

    It redirects to /myController/muAction/...?param1=val1&param2=val2

    This is true at least in CakePHP 1.3

    0 讨论(0)
  • 2020-12-24 12:54

    I do not know why I was not able to find this in the CakePHP documentation, but I did finally figure out the solution. I am posting it here in case anyone else has the same problem. (If someone knows where this is in the documentation please post it as well, thanks!)

    To redirect to the URL:

    http://www.example.com/myController/myAction/param1:val1/param2:val2

    You can use:

    $this->redirect(array("controller" => "myController", 
                          "action" => "myAction",
                          "param1" => "val1",
                          "param2" => "val2",
                          $data_can_be_passed_here),
                    $status,
                    $exit);
    

    Hope it helps!

    0 讨论(0)
  • 2020-12-24 12:54

    Instead, you can use this format also

    <?php
    
    $this->redirect('/controller/action/par1:par1/par2:par2/');
    
    
    ?>
    
    <?php
    
    $this->redirect('/controller/action/id/10/name/hello/');
    
    ?>
    
    0 讨论(0)
提交回复
热议问题