php8.5
Home/ Manual/ yaf / yaf_plugin_abstract/ Yaf_Plugin_Abstract::preDispatch

Yaf_Plugin_Abstract::preDispatch

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Hook before each dispatch

Description

Yaf_Plugin_Abstract::preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void

This hook is triggered before each dispatch iteration in the dispatch loop. A dispatch loop may run several iterations, so this hook may be called more than once per request.

Parameters

request

The Yaf_Request_Abstract instance being dispatched.

response

The Yaf_Response_Abstract instance.

Return Values

No value is returned.

Examples

Yaf_Plugin_Abstract::preDispatch example

php
<?php
class LayoutPlugin extends Yaf_Plugin_Abstract
{
    public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
    {
        /* pick the template directory based on the module, right
         * before the action is dispatched */
        $view = Yaf_Dispatcher::getInstance()->getView();
        if ($request->getModuleName() == "Admin") {
            $view->setScriptPath(APPLICATION_PATH . "/modules/admin/views");
        }
    }
}

/* plugins are registered in the bootstrap */
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initPlugin(Yaf_Dispatcher $dispatcher)
    {
        $dispatcher->registerPlugin(new LayoutPlugin());
    }
}
?>

See Also

  • Yaf_Plugin_Abstract::routerStartup
  • Yaf_Plugin_Abstract::routerShutdown
  • Yaf_Plugin_Abstract::dispatchLoopStartup
  • Yaf_Plugin_Abstract::postDispatch
  • Yaf_Plugin_Abstract::dispatchLoopShutdown
  • Yaf_Plugin_Abstract::preResponse

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