
Untitled
By: a guest on
May 29th, 2012 | syntax:
PHP | size: 0.86 KB | hits: 15 | expires: Never
class Module
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function onBootstrap($e)
{
// Register a dispatch event
$app = $e->getParam('application');
$app->events()->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'setErrorLayout'), 100);
$services = $app->getServiceManager();
$view = $services->get('Zend\View\View');
$jsonStrategy = $services->get('ViewJsonStrategy');
$view->events()->attach($jsonStrategy, 100);
}
public function setErrorLayout($e) {
// Set the layout template
$viewModel = $e->getViewModel();
$viewModel->setTemplate('layout/error');
}
}
// In the controller
class FooController extends ActionController {
public function barAction()
{
return new JsonModel(array(
'result' => 'Success!'
));
}
}