Example #1
0
 /**
  * Show add view or add a new page
  * @return \Zend\View\Model\ViewModel
  */
 public function addAction()
 {
     $config = $this->getServiceLocator()->get('Configuration');
     //init used variables
     $form = new MultiForm(array('page' => new Page($config['dots-pages']['templates']), 'meta' => new PageMeta()));
     $request = $this->getRequest();
     //on post return the response as a json string
     if ($request->getMethod() == 'POST') {
         //handle form errors
         $errorResponse = $this->handleErrors($form);
         if ($errorResponse) {
             return $errorResponse;
         }
         //get the form values
         $data = $form->getInputFilter()->getValues();
         //save the page entity
         $page = new Entity\Page();
         $page->populate($data['page']);
         $page->save();
         //save the page meta
         $meta = new Entity\PageMeta();
         $meta->populate($data['meta']);
         $meta->expires_after = empty($meta->expires_after) ? null : $meta->expires_after;
         $meta->page_id = $page->id;
         $meta->save();
         return $this->jsonResponse(array('success' => true, 'action' => 'window.location = "/' . urlencode($page->alias) . '";'));
     }
     return $this->getTerminalView(array('form' => $form));
 }