Pop\Mvc\Controller::dispatch PHP Method

dispatch() public method

Dispatch the controller based on the action
public dispatch ( string $action = 'index' ) : Controller
$action string
return Controller
    public function dispatch($action = 'index')
    {
        if (method_exists($this, $action)) {
            if (null !== $this->project->logger()) {
                $this->project->log("Dispatch ['" . get_class($this) . "']->" . $action . "\t" . $this->request->getRequestUri() . "\t" . $this->request->getFullUri(), time());
            }
            $this->{$action}();
        } else {
            throw new Exception('That action is not defined in the controller.');
        }
    }

Usage Example

Beispiel #1
0
 public function testDispatchException()
 {
     $this->setExpectedException('Pop\\Mvc\\Exception');
     $c = new Controller();
     $c->dispatch();
 }