public function newAction()
 {
     //get CategoryTable thong qua TableGateway va truyen vao PostForm()
     $table = $this->getServiceLocator()->get('Blog\\Model\\CategoryTable');
     $form = new PostForm($table);
     //        print "<pre>";
     //            print_r($form);
     //            exit();
     $form->get('submit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = new Post();
         $form->setInputFilter($post->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $post->exchangeArray($form->getData());
             $this->getPostTable()->savePost($post);
             return $this->redirect()->toRoute('posts');
         }
     }
     return array('form' => $form);
 }
 public function addAction()
 {
     $formPost = new PostForm($this->categoryTable);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = new Post();
         $formPost->setInputFilter($post->getInputFilter());
         $nonFiles = $this->getRequest()->getPost()->toArray();
         $files = $this->getRequest()->getFiles()->toArray();
         // Pour ZF 2.2.x uniquement
         $data = array_merge_recursive($nonFiles, $files);
         $formPost->setData($data);
         if ($formPost->isValid()) {
             $size = new Size(array('max' => 716800));
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $adapter->setValidators(array($size), $files['image']);
             if (!$adapter->isValid()) {
                 $dataError = $adapter->getMessages();
                 $error = array();
                 foreach ($dataError as $key => $row) {
                     $error[] = $row;
                 }
                 $formPost->setMessages(array('image' => $error));
             } else {
                 $adapter->setDestination('./public/img/');
                 if ($adapter->receive($files['image']['name'])) {
                     $post->exchangeArray($formPost->getData());
                     $post->image = $files['image']['name'];
                     $this->postTable->savePost($post);
                     return $this->redirect()->toRoute('home');
                 }
             }
         }
     }
     return new ViewModel(array('form' => $formPost));
 }