1 <?php
2
3 namespace Balance\Mvc\Controller;
4
5 use Exception;
6 use Zend\Mvc\Controller\AbstractActionController;
7 use Zend\View\Model\ViewModel;
8
9 10 11
12 trait IndexActionTrait
13 {
14 15 16 17 18
19 public function indexAction()
20 {
21
22 if (! $this instanceof AbstractActionController) {
23
24 throw new Exception('Invalid Controller');
25 }
26
27 if (! $this instanceof ModelAwareInterface) {
28
29 throw new Exception('Invalid Controller');
30 }
31
32 $model = $this->getModel();
33
34 $params = $this->getRequest()->getQuery();
35
36 $elements = $model->fetch($params);
37
38 $this->getServiceLocator()->get('ViewManager')
39 ->getInjectTemplateListener()->setPreferRouteMatchController(true);
40
41 return new ViewModel(array(
42 'elements' => $elements,
43 'form' => $model->getFormSearch(),
44 'params' => $params,
45 ));
46 }
47 }
48