htnux
htnux

Reputation: 63

ZF2 - stop executing after forward

If there are any errors after validations, I forward back to input controller, and if there is no error, continue success controller.

In ZF1, I was able to do this because fowarding in preDispatch() doesn't execute called action like following:

public function preDispatch()
{
    parent::preDispatch();
    if ($action == 'success' && $this->validate() === false) {
        $this->_forward('input');
    }
}

public function successAction()
{
}

public function inputAction()
{
}

In ZF2, I am trying to attach validations on dispatch and forwarding if any errors, but ZF2 continues to execute, so inputAction and successAction are both called.

$events->attach('dispatch', function (MvcEvent $e) use ($controller) {
    $result = $this->validate($controller);
    if ($result->isValid() === false) {
        $callingClassName = get_class($this);
        $test = $controller->forward()->dispatch($callingClassName, array('action' => 'input'));
    }
}

Any solutions for this? I just want to stop executing after forward...

I know returning ViewModel in successAction stops anymore reads, but I want to make it commonly usable.

Upvotes: 1

Views: 1164

Answers (1)

Weteef
Weteef

Reputation: 1002

I guess you are looking for

$e->stopPropagation();

This stops further event propagation.

Upvotes: 3

Related Questions