Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 29th, 2012  |  syntax: PHP  |  size: 0.86 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Module
  2. {
  3.  
  4.         public function getConfig()
  5.         {
  6.                 return include __DIR__ . '/config/module.config.php';
  7.         }
  8.  
  9.         public function onBootstrap($e)
  10.         {
  11.                 // Register a dispatch event
  12.                 $app = $e->getParam('application');
  13.                 $app->events()->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'setErrorLayout'), 100);
  14.  
  15.       $services     = $app->getServiceManager();
  16.       $view         = $services->get('Zend\View\View');
  17.       $jsonStrategy = $services->get('ViewJsonStrategy');
  18.       $view->events()->attach($jsonStrategy, 100);
  19.         }
  20.  
  21.         public function setErrorLayout($e) {
  22.                 // Set the layout template
  23.                 $viewModel = $e->getViewModel();
  24.                 $viewModel->setTemplate('layout/error');
  25.         }
  26. }
  27.  
  28.  
  29. // In the controller
  30. class FooController extends ActionController {
  31.         public function barAction()
  32.         {
  33.                 return new JsonModel(array(
  34.                         'result' => 'Success!'
  35.                 ));
  36.         }
  37. }