public function __construct($tableName, $entityClass)
 {
     $this->dbAdapter = Registry::getService('Zend\\Db\\Adapter\\Adapter');
     $this->tableName = $tableName;
     $this->tableGateway = new TableGateway($this->tableName, $this->dbAdapter);
     $this->entityClass = $entityClass;
 }
示例#2
0
 public function delete($id)
 {
     $repository = Registry::getEntityRepository($this->entityClass);
     $entity = $repository->findById($id);
     $methodNamePrimaryKey = MyHydrator::generateGetMethod($entity::PRIMARY_KEY);
     $primaryKeyValue = $entity->{$methodNamePrimaryKey}();
     $this->tableGateway->delete(array($entity::PRIMARY_KEY => $primaryKeyValue));
     return;
 }
 public function deletarAction()
 {
     $id = (int) $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toUrl($this->redirect);
     }
     $entity = new $this->entityClass();
     // Instancia o servico e verifica se existe uma pre verificacao a ser executada
     $service = Registry::getEntityService($this->entityClass);
     $service->delete($id);
     return $this->redirect()->toUrl($this->redirect);
 }