PHP 8.4.26 Released!

Yaf_Controller_Abstract::forward

(Yaf >=1.0.0)

Yaf_Controller_Abstract::forward — Forward the current request to another action

Beschreibung

public function Yaf_Controller_Abstract::forward(string $action, ?array $parameters = ?): ?bool
public function Yaf_Controller_Abstract::forward(string $controller, string $action, ?array $parameters = ?): ?bool
public function Yaf_Controller_Abstract::forward(
    string $module,
    string $controller,
    string $action,
    ?array $parameters = ?
): ?bool

Forward the current request to another action. The target is determined from the number and types of the arguments:

  • action only: forward to another action of the current controller.
  • controller and action: forward to another controller.
  • module, controller and action: forward to another module.
  • The optional parameters array carries invocation arguments retrievable with Yaf_Request_Abstract::getParam().

Hinweis:

This method does not switch to the destination action immediately; the switch takes place after the current flow finishes. To hand over control right away, return from the current action method (returning false also tells Yaf not to auto-render the current view).

Parameter-Liste

module

The destination module name. If the current module is given, it is used as is.

controller

The destination controller name.

action

The destination action name.

parameters

Invocation arguments for the destination action, retrievable with Yaf_Request_Abstract::getParam().

Rückgabewerte

Returns true on success, or false / null on failure.

Beispiele

Beispiel #1 Yaf_Controller_Abstract::forward() example

<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction() {
        $logined = $_SESSION["login"];
        if (!$logined) {
            $this->forward("login", array("from" => "Index")); // forward to the login action
            return false; // this is important, it ends the current flow
                          // and tells Yaf not to auto-render
        }

        // other processes
    }

    public function loginAction() {
        echo "login, redirected from ", $this->_request->getParam("from") , " action";
    }
}
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

login, redirected from Index action

Siehe auch

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top