2013-05-01 52 views
0

我有一个控制器可以保存一些数据。查看模块异常策略

$pat = $sm->get('Tables\PaymentAttemptsTable'); 
$pat->save($post); 

模块配置具有以下配置:

public function onBootstrap(EventInterface $e) 
{ 
    $em = $e->getApplication()->getEventManager(); 
    $em->attach('dispatch', array($this, 'loadConfiguration'), 100); 
} 

public function loadConfiguration(EventInterface $e) 
{ 
    $sm = $e->getApplication()->getServiceManager(); 

    //if this module 
    $exceptionstrategy = $sm->get('ViewManager')->getExceptionStrategy(); 
    $exceptionstrategy->setExceptionTemplate('error/inserterror'); 
} 

在PaymentAttemptsTable模块CONFI我有一个类似的策略是这样的。

public function onBootstrap(EventInterface $e) 
{ 
    $eventManager  = $e->getApplication()->getEventManager(); 
    $eventManager->attach('dispatch', array($this, 'loadConfiguration'), 100); 
} 

public function loadConfiguration(EventInterface $e) 
{ 
    $sm = $e->getApplication()->getServiceManager(); 

    //if this module 
    $exceptionstrategy = $sm->get('ViewManager')->getExceptionStrategy(); 
    $exceptionstrategy->setExceptionTemplate('error/saveerror'); 
} 

在每一个我都有这样的看法confi。

return array(

'view_manager' => array(
    'exception_template'  => 'error/index', 
    'template_map' => array(
     'error/index'    => __DIR__ . '/../view/error/index.phtml', 
    ), 
    'template_path_stack' => array(
     __DIR__ . '/../view', 
    ), 
), 

);

的事情是,当我在PaymentAttemptsTable类做

throw new SaveError('Table must be a string or instance of TableIdentifier.'); 

我从控制器获得的模板,并不会形成表类,是有办法解决这一问题?

回答

0

如果你看看 http://framework.zend.com/manual/2.0/en/modules/zend.view.quick-start.html

控制器和视图模型部分它表明你如何加载不同的视图模板,你需要做的是视图模板更改为需要加载的一个在PaymentAttemptsTable类中。这将需要在呼叫控制器中完成。从Zend.com

namespace Foo\Controller; 

use Zend\Mvc\Controller\AbstractActionController; 
use Zend\View\Model\ViewModel; 

class BazBatController extends AbstractActionController 
{ 
    public function doSomethingCrazyAction() 
    { 
     $view = new ViewModel(array(
      'message' => 'Hello world', 
     )); 
     $view->setTemplate('foo/baz-bat/do-something-crazy'); 
     return $view; 
    } 
} 
+0

例子,我认为这是罚款正常视图模板,但我需要的是一个异常的策略,即当异常平米使用某些模板。 – gastoncs 2013-05-01 22:30:07

+0

啊,我明白了,我很抱歉,我无法帮助你。尽管如果你在try catch块中做了它,你可以在catch中应用模板更改。我知道的不是一个很整洁的方式,但我甚至不确定有内置的方法来实现这一点。 – mic 2013-05-02 07:17:51