php8.5
Home/ Manual/ yaf / yaf_request_abstract/ Yaf_Request_Abstract::setDispatched

Yaf_Request_Abstract::setDispatched

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Mark the request as dispatched

Description

Yaf_Request_Abstract::setDispatched(bool $flag = true): Yaf_Request_Abstract

Mark the request as dispatched

This is called by the dispatcher after an action is executed; it stops the dispatch loop. It can be called manually, e.g. to skip the remaining dispatch iterations.

Parameters

flag

The state to set. Defaults to true.

Return Values

Returns the request object itself.

Examples

Yaf_Request_Abstract::setDispatched example

php
<?php
class AuthPlugin extends Yaf_Plugin_Abstract
{
    public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
    {
        if (empty($_SESSION["user_id"])) {
            // Skip the requested action and redirect to the login page
            $request->setDispatched();
            $response->setRedirect("/account/login");
        }
    }
}
?>

See Also

  • Yaf_Request_Abstract::isDispatched
  • Yaf_Dispatcher::dispatch

Source: reference/yaf/yaf_request_abstract/setdispatched.xml · from the official PHP manual (php/doc-en)