public function editAction()
 {
     $id = (int) $this->params('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('profile', array('action' => 'add'));
     }
     $table = $this->getProfileTable();
     try {
         $profile = $table->get($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('profile');
     }
     $form = new \Application\Form\User();
     $form->bind($profile);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($profile->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $table->save($profile);
             return $this->redirect()->toRoute('profile');
         }
     }
     return new ViewModel(array('id' => $id, 'form' => $form));
 }
 public function addAction()
 {
     $form = new User();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $entity = new Profile();
         $form->setInputFilter($entity->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $entity->exchangeArray($form->getData());
             $table = $this->getProfileTable()->save($entity);
             return $this->redirect()->toRoute('profile');
         }
     }
     return new ViewModel(array('form' => $form));
 }