llpereiras

Zf2 - getModel

Nov 21st, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. // CrudController, todo controller estende esse controller
  2. /********* Metodo Antigo ***********************
  3. //protected function getModelAntigo($name)
  4. //  {
  5. //      $class = '\Application\Model\\'.ucfirst($name).'Model';
  6. //      return new $class($this->getAdapter(), $this->getServiceLocator());
  7. //  }
  8. //*************************************************
  9. public function getModel($name)
  10.     {
  11.     return $this->getServiceLocator()->get($name.'Model');
  12.     }
  13.    
  14.  
  15. // Application/Module.php
  16. public function getServiceConfig()
  17.    {
  18.        return array(
  19.            'factories' => array(
  20.                'AulaModel'  => function($sm) {
  21.             return new \Application\Model\AulaModel($sm->get('Zend\Db\Adapter\Adapter'),$sm);
  22.         },
  23.         'AulaModeloModel'   => function($sm) {
  24.             return new \Application\Model\AulaModeloModel($sm->get('Zend\Db\Adapter\Adapter'),$sm);
  25.         },
  26.         'CapituloModeloModel'   => function($sm) {
  27.             return new \Application\Model\CapituloModeloModel($sm->get('Zend\Db\Adapter\Adapter'),$sm);
  28.         },
  29.         'CapituloModel'     => function($sm) {
  30.             return new \Application\Model\CapituloModel($sm->get('Zend\Db\Adapter\Adapter'),$sm);
  31.         },
  32.            ),
  33.        );
  34.    }
Advertisement
Add Comment
Please, Sign In to add comment