Class Phalcon\Mvc\Dispatcher

extends abstract class Phalcon\Dispatcher

implements Phalcon\Events\EventsAwareInterface, Phalcon\Di\InjectionAwareInterface, Phalcon\DispatcherInterface, Phalcon\Mvc\DispatcherInterface

Source on GitHub

Dispatching is the process of taking the request object, extracting the module name, controller name, action name, and optional parameters contained in it, and then instantiating a controller and calling an action of that controller.

$di = new \Phalcon\Di();

$dispatcher = new \Phalcon\Mvc\Dispatcher();

$dispatcher->setDI($di);

$dispatcher->setControllerName("posts");
$dispatcher->setActionName("index");
$dispatcher->setParams([]);

$controller = $dispatcher->dispatch();

Constants

integer EXCEPTION_NO_DI

integer EXCEPTION_CYCLIC_ROUTING

integer EXCEPTION_HANDLER_NOT_FOUND

integer EXCEPTION_INVALID_HANDLER

integer EXCEPTION_INVALID_PARAMS

integer EXCEPTION_ACTION_NOT_FOUND

Methods

public setControllerSuffix (mixed $controllerSuffix)

Sets the default controller suffix

public setDefaultController (mixed $controllerName)

Sets the default controller name

public setControllerName (mixed $controllerName)

Sets the controller name to be dispatched

public getControllerName ()

Gets last dispatched controller name

public getPreviousNamespaceName ()

Gets previous dispatched namespace name

public getPreviousControllerName ()

Gets previous dispatched controller name

public getPreviousActionName ()

Gets previous dispatched action name

protected _throwDispatchException (mixed $message, [mixed $exceptionCode])

Throws an internal exception

protected _handleException (Exception $exception)

Handles a user exception

public getControllerClass ()

Possible controller class name that will be located to dispatch the request

public getLastController ()

Returns the latest dispatched controller

public getActiveController ()

Returns the active controller in the dispatcher

public setDI (Phalcon\DiInterface $dependencyInjector) inherited from Phalcon\Dispatcher

Sets the dependency injector

public getDI () inherited from Phalcon\Dispatcher

Returns the internal dependency injector

public setEventsManager (Phalcon\Events\ManagerInterface $eventsManager) inherited from Phalcon\Dispatcher

Sets the events manager

public getEventsManager () inherited from Phalcon\Dispatcher

Returns the internal event manager

public setActionSuffix (mixed $actionSuffix) inherited from Phalcon\Dispatcher

Sets the default action suffix

public getActionSuffix () inherited from Phalcon\Dispatcher

Gets the default action suffix

public setModuleName (mixed $moduleName) inherited from Phalcon\Dispatcher

Sets the module where the controller is (only informative)

public getModuleName () inherited from Phalcon\Dispatcher

Gets the module where the controller class is

public setNamespaceName (mixed $namespaceName) inherited from Phalcon\Dispatcher

Sets the namespace where the controller class is

public getNamespaceName () inherited from Phalcon\Dispatcher

Gets a namespace to be prepended to the current handler name

public setDefaultNamespace (mixed $namespaceName) inherited from Phalcon\Dispatcher

Sets the default namespace

public getDefaultNamespace () inherited from Phalcon\Dispatcher

Returns the default namespace

public setDefaultAction (mixed $actionName) inherited from Phalcon\Dispatcher

Sets the default action name

public setActionName (mixed $actionName) inherited from Phalcon\Dispatcher

Sets the action name to be dispatched

public getActionName () inherited from Phalcon\Dispatcher

Gets the latest dispatched action name

public setParams (array $params) inherited from Phalcon\Dispatcher

Sets action params to be dispatched

public getParams () inherited from Phalcon\Dispatcher

Gets action params

public setParam (mixed $param, mixed $value) inherited from Phalcon\Dispatcher

Set a param by its name or numeric index

public mixed getParam (mixed $param, [string | array $filters], [mixed $defaultValue]) inherited from Phalcon\Dispatcher

Gets a param by its name or numeric index

public boolean hasParam (mixed $param) inherited from Phalcon\Dispatcher

Check if a param exists

public getActiveMethod () inherited from Phalcon\Dispatcher

Returns the current method to be/executed in the dispatcher

public isFinished () inherited from Phalcon\Dispatcher

Checks if the dispatch loop is finished or has more pendent controllers/tasks to dispatch

public setReturnedValue (mixed $value) inherited from Phalcon\Dispatcher

Sets the latest returned value by an action manually

public mixed getReturnedValue () inherited from Phalcon\Dispatcher

Returns value returned by the latest dispatched action

public setModelBinding (mixed $value, [mixed $cache]) inherited from Phalcon\Dispatcher

Enable/Disable model binding during dispatch

$di->set('dispatcher', function() {
    $dispatcher = new Dispatcher();

    $dispatcher->setModelBinding(true, 'cache');
    return $dispatcher;
});

public setModelBinder (Phalcon\Mvc\Model\BinderInterface $modelBinder, [mixed $cache]) inherited from Phalcon\Dispatcher

Enable model binding during dispatch

$di->set('dispatcher', function() {
    $dispatcher = new Dispatcher();

    $dispatcher->setModelBinder(new Binder(), 'cache');
    return $dispatcher;
});

public getModelBinder () inherited from Phalcon\Dispatcher

Gets model binder

public object dispatch () inherited from Phalcon\Dispatcher

Dispatches a handle action taking into account the routing parameters

protected object _dispatch () inherited from Phalcon\Dispatcher

Dispatches a handle action taking into account the routing parameters

public forward (array $forward) inherited from Phalcon\Dispatcher

Forwards the execution flow to another controller/action Dispatchers are unique per module. Forwarding between modules is not allowed

$this->dispatcher->forward(
    [
        "controller" => "posts",
        "action"     => "index",
    ]
);

public wasForwarded () inherited from Phalcon\Dispatcher

Check if the current executed action was forwarded by another one

public getHandlerClass () inherited from Phalcon\Dispatcher

Possible class name that will be located to dispatch the request

public callActionMethod (mixed $handler, mixed $actionMethod, [array $params]) inherited from Phalcon\Dispatcher

...

public getBoundModels () inherited from Phalcon\Dispatcher

Returns bound models from binder instance

class UserController extends Controller
{
    public function showAction(User $user)
    {
        $boundModels = $this->dispatcher->getBoundModels(); // return array with $user
    }
}

protected _resolveEmptyProperties () inherited from Phalcon\Dispatcher

Set empty properties to their defaults (where defaults are available)

© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Dispatcher.html