Пример #1
0
 public function addAction()
 {
     $this->init();
     $form = new BankForm();
     $form->get('submit')->setValue('Add');
     //$id = (int) $this->params()->fromRoute('id', 0);
     //if($id) {
     //$form->get('id')->setValue($id );
     //$bank = $this->getBankTable()->getBank($id);
     //}
     $request = $this->getRequest();
     if ($request->isPost()) {
         $bank = new Bank();
         $form->setInputFilter($bank->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $name = $request->getPost('name');
             $price = $request->getPost('price');
             $active = $request->getPost('active');
             $dataArr['name'] = $name;
             $dataArr['bucks'] = $request->getPost('bucks');
             $dataArr['price'] = $price;
             $dataArr['gold_coins'] = $request->getPost('gold_coins');
             $dataArr['created_on'] = date("Y-m-d");
             $dataArr['active'] = $request->getPost('active');
             $bank->exchangeArray($dataArr);
             $this->getBankTable()->saveBank($bank);
             $this->flashMessenger()->addMessage('Your submission has been added successfully !');
             return $this->redirect()->toRoute('bank', array('action' => 'index'));
         }
     }
     return array('form' => $form, 'bank' => $form, 'messages' => $this->flashmessenger()->getMessages());
 }
Пример #2
0
 public function save(Bank $bank)
 {
     $data = array('name' => $bank->getName(), 'description' => $bank->getDescription());
     $id = (int) $bank->getId();
     $params = array();
     $params['table'] = $this->tableGateway->getTableName();
     $params['operation'] = 1;
     $params['data'] = json_encode($data);
     if ($id == 0) {
         $this->tableGateway->insert($data);
         $id = $this->tableGateway->getLastInsertValue();
         if ($id) {
             $params['id'] = $id;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             return true;
         } else {
             return false;
         }
     } else {
         if ($this->get($id)) {
             $params['id'] = $id;
             $params['operation'] = 2;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             $this->tableGateway->update($data, array('id' => $id));
             return true;
         } else {
             return false;
         }
     }
 }
Пример #3
0
 public function addAction()
 {
     $form = new BankForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $bank = new Bank();
         $form->setInputFilter($bank->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $bank->exchangeArray($form->getData());
             $result = $this->getBankTable()->save($bank);
             return $this->redirect()->toRoute('admin/bank');
         }
     }
     return array('form' => $form, 'config' => $this->config);
 }