/**
  * @return \Zend\Http\Response|ViewModel
  */
 public function detailAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     $isClone = $this->params()->fromQuery('action', '');
     $helper = new ConstantHelper($this->getDbAdapter());
     $form = $helper->getForm();
     $constant = $this->constantTable()->getConstant($id);
     $form->setAttribute("class", "form-horizontal");
     $isEdit = true;
     if (!$constant) {
         $isEdit = false;
         $constant = new Constant();
     }
     if ($constant && $isClone == 'clone') {
         $isEdit = false;
         $id = 0;
         $constant->setConstantId($id);
     }
     $form->bind($constant);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($helper->getInputFilter($id));
         $post_data = $request->getPost()->toArray();
         $form->setData($post_data);
         if ($form->isValid()) {
             $this->constantTable()->saveConstant($constant);
             $this->flashMessenger()->addSuccessMessage('Save successful');
             return $this->redirect()->toRoute('constant');
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id, 'isEdit' => $isEdit));
 }
 /**
  * @param Constant $constant
  * @return Constant
  */
 public function saveConstant(Constant $constant)
 {
     $id = $constant->getConstantId();
     $data = $constant->getArrayCopy();
     if ($id > 0) {
         $this->update($data, array('constantId' => $id));
     } else {
         unset($data['constantId']);
         $this->insert($data);
     }
     if (!$constant->getConstantId()) {
         $constant->setConstantId($this->getLastInsertValue());
     }
     return $constant;
 }