2013-03-12 44 views
1

如果驗證後有任何錯誤,我將轉發回輸入控制器,如果沒有錯誤,則繼續成功控制器。ZF2 - 轉發後停止執行

在ZF1,我能做到這一點,因爲在preDispatch fowarding()不執行所謂的動作像如下:

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

public function successAction() 
{ 
} 

public function inputAction() 
{ 
} 

在ZF2,我想附上調度驗證和轉發如有錯誤,但ZF2繼續執行,所以inputAction和successAction都被調用。

$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')); 
    } 
} 

任何解決方案? 我只是想在轉發後停止執行...

我知道在successAction中返回ViewModel會停止閱讀,但我想使其通用。

回答

3

我猜你正在尋找

$e->stopPropagation(); 

這將停止進一步的事件傳播。

+0

超級!非常感謝。 – htnux 2013-03-13 03:26:03