public function addAction()
 {
     $sessionContainer = new Container();
     $userData = $sessionContainer->offsetGet("user");
     //var_dump($this->getRequest()->getPost());
     $parames = $this->getRequest()->getPost();
     $data = iterator_to_array($parames);
     $data['writer'] = $userData["username"];
     $post = new Post();
     $post->exchangeArray($data);
     $res = $this->getPostTable()->insert($post);
     //为什么tablegateway插入成功的返回值为null?
     $this->redirect()->toRoute("forum", ["controller" => "index", "action" => "index"]);
 }
Example #2
0
 public function threadAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         echo "Thread not found.<br>";
         return $this->redirect()->toRoute('forum', array('action' => 'index'));
     }
     $form = new PostForm();
     $form->get('submit')->setValue('Reply');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = new Post();
         // getInputFilter()
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $post->exchangeArray($form->getData());
             $this->getPostList()->createPost($post, $id);
             // next line needed or text stays in box - must be better way?
             return $this->redirect()->toRoute('thread', array('id' => $id));
         }
     }
     return array('thread' => $this->getThreadList()->getThread($id), 'posts' => $this->getPostList()->getThreadPosts($id), 'form' => $form);
 }