{IT} - 3.5.3.2.1 redirect

redirect(string $url, integer $status, boolean $exit)

Il metodi di controllo del flusso usato più spesso è redirect(). Questo metodo prende il primo parametro nella form di un indirizzo CakePHP-URL. Quando un utente ha ordinato correttamente qualcosa, vorresti ridirezionarlo ad una schermata di ricevuta d'ordine.

function placeOrder() {

    //Logic for finalizing order goes here

    if($success) {
        $this->redirect(array('controller' => 'orders', 'action' => 'thanks'));
    } else {
        $this->redirect(array('controller' => 'orders', 'action' => 'confirm'));
    }
}
  1. function placeOrder() {
  2. //Logic for finalizing order goes here
  3. if($success) {
  4. $this->redirect(array('controller' => 'orders', 'action' => 'thanks'));
  5. } else {
  6. $this->redirect(array('controller' => 'orders', 'action' => 'confirm'));
  7. }
  8. }

Il secondo parametro di redirect() permette di definire uno stato HTTP per accompagnare il redirect. Potresti utilizzare 301 (moved permanently) o 303 (see other), a seconda della natura del redirect.

Il metodo userà un exit() dopo il redirect a meno che non si è settato il terzo parametro a false.

{EN} - 3.5.3.2.1 redirect

redirect(string $url, integer $status, boolean $exit)

The flow control method you’ll use most often is redirect(). This method takes its first parameter in the form of a CakePHP-relative URL. When a user has successfully placed an order, you might wish to redirect them to a receipt screen.

function placeOrder() {

    //Logic for finalizing order goes here

    if($success) {
        $this->redirect(array('controller' => 'orders', 'action' => 'thanks'));
    } else {
        $this->redirect(array('controller' => 'orders', 'action' => 'confirm'));
    }
}
  1. function placeOrder() {
  2. //Logic for finalizing order goes here
  3. if($success) {
  4. $this->redirect(array('controller' => 'orders', 'action' => 'thanks'));
  5. } else {
  6. $this->redirect(array('controller' => 'orders', 'action' => 'confirm'));
  7. }
  8. }

The second parameter of redirect() allows you to define an HTTP status code to accompany the redirect. You may want to use 301 (moved permanently) or 303 (see other), depending on the nature of the redirect.

The method will issue an exit() after the redirect unless you set the third parameter to false.

Differences

Lines: 1-7Lines: 1-7
 <title>redirect</title> <title>redirect</title>
 <p class="method"><code>redirect(string $url, integer $status, boolean $exit)</code></p> <p class="method"><code>redirect(string $url, integer $status, boolean $exit)</code></p>
-<p>The flow control method you’ll use most often is <code>redirect()</code>. This method takes its first parameter in the form of a CakePHP-relative URL. When a user has successfully placed an order, you might wish to redirect them to a receipt screen.</p> +<p>Il metodi di controllo del flusso usato più spesso è redirect(). Questo metodo prende il primo parametro nella form di un indirizzo CakePHP-URL. Quando un utente ha ordinato correttamente qualcosa, vorresti ridirezionarlo ad una schermata di ricevuta d'ordine.</p>
 <pre> <pre>
 function placeOrder() { function placeOrder() {
  //Logic for finalizing order goes here  //Logic for finalizing order goes here
Lines: 12-17Lines: 12-17
  $this-&gt;redirect(array('controller' =&gt; 'orders', 'action' =&gt; 'confirm'));  $this-&gt;redirect(array('controller' =&gt; 'orders', 'action' =&gt; 'confirm'));
  }  }
 } }
 </pre> </pre>
-<p>The second parameter of <code>redirect()</code&gt; allows you to define an HTTP status code to accompany the redirect. You may want to use 301 (moved permanently) or 303 (see other), depending on the nature of the redirect.</p>
<p>The method will issue an <code>exit()</code> after the redirect unless you set the third parameter to <code>false</code>.</p>
+<p>Il secondo parametro di redirect() permette di definire uno stato HTTP per accompagnare il redirect. Potresti utilizzare 301 (moved permanently) o 303 (see other), a seconda della natura del redirect.</p>
<p>Il metodo use un exit() dopo il redirect a meno che non si è settato il terzo parametro a false.</p>