コード例 #1
0
 /**
  * Добавляет новую должность
  */
 public function addAction()
 {
     $result = array();
     $presentPost = \Posts::findFirst("title='" . $this->request->get("title") . "'");
     if ($presentPost != false) {
         $result['retcode'] = 1;
         $result['msgs'][] = "Посада із такою назвою вже існує!";
     } else {
         $namePost = new \Posts();
         $namePost->title = $this->request->get("title");
         if ($namePost->save() == false) {
             $result['retcode'] = 2;
             $result['msgs'][] = "Неможливо додати посаду \n";
             foreach ($namePost->getMessages() as $message) {
                 $result['msgs'][] = $message + "\n";
             }
         } else {
             $result['retcode'] = 0;
             $result['id'] = $namePost->id;
             $result['msgs'][] = "Нову посаду збережено";
         }
     }
     $this->view->disable();
     $this->response->setContentType('application/json', 'UTF-8');
     echo json_encode($result);
 }
コード例 #2
0
 public function createAction()
 {
     $post = new Posts();
     $success = $post->save($this->request->getPost(), array('id_posta', 'poruka', 'created_at'));
     if ($success) {
         echo "Your message has been posted !";
     } else {
         echo "Sorry, the following problems were generated: ";
         foreach ($post->getMessages() as $message) {
             echo $message->getMessage(), "<br/>";
         }
     }
     $this->view->disable();
 }
コード例 #3
0
 public function createAction()
 {
     $entity = new \Posts();
     $createForm = new AutoForm($entity);
     if ($this->request->isPost()) {
         $created = $entity->create($this->request->getPost());
         if (!$created) {
             foreach ($entity->getMessages() as $message) {
                 $this->flashSession->error($message);
             }
         }
         return $this->dispatcher->forward(['action' => 'index']);
     }
     $this->view->setVars(['testForm' => $createForm]);
 }
コード例 #4
0
 /**
  * Creates a new post
  */
 public function create($latitude, $longitude, $content, $user)
 {
     $post = new Posts();
     $post->users_id = $user->id;
     $post->latitude = $latitude;
     $post->longitude = $longitude;
     $post->content = $content;
     if ($post->save()) {
         return array(true, $post->toArray());
     } else {
         $errors = array();
         foreach ($post->getMessages() as $message) {
             $errors[] = (string) $message;
         }
         return array(false, $errors);
     }
 }
コード例 #5
0
 public function savePostAction()
 {
     $this->view->title = "Збереження посади";
     $errors = array();
     if ($this->request->isPost()) {
         $namePost = new \Posts();
         $namePost->title = $this->request->get("title");
         if ($namePost->save() == false) {
             echo "Неможливо додати посаду \n";
             foreach ($namePost->getMessages() as $message) {
                 echo $message, "\n";
             }
         } else {
             $response = new \Phalcon\Http\Response();
             $response->redirect("/methodist/stafflist/posts");
             return $response;
         }
     }
 }
コード例 #6
0
 /**
  * Creates a new post
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "posts", "action" => "index"));
     }
     $post = new Posts();
     $post->title = $this->request->getPost("title");
     $post->body = $this->request->getPost("body");
     $post->excerpt = $this->request->getPost("excerpt");
     $post->published = $this->request->getPost("published");
     $post->updated = $this->request->getPost("updated");
     $post->pinged = $this->request->getPost("pinged");
     $post->to_ping = $this->request->getPost("to_ping");
     if (!$post->save()) {
         foreach ($post->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "posts", "action" => "new"));
     }
     $this->flash->success("post was created successfully");
     return $this->dispatcher->forward(array("controller" => "posts", "action" => "index"));
 }
コード例 #7
0
 /**
  * Creates a new post
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "posts", "action" => "index"));
     }
     $post = new Posts();
     $postTags = array();
     $post->id = $this->request->getPost("id");
     $post->tags = $postTags;
     $post->users_id = $this->session->get("user_id");
     $post->title = $this->request->getPost("title");
     $post->body = $this->request->getPost("body");
     $post->excerpt = $this->request->getPost("excerpt");
     $post->pinged = $this->request->getPost("pinged");
     $post->to_ping = $this->request->getPost("to_ping");
     $success = $post->save();
     $tags = explode(",", $this->request->getPost("tags", array("trim", "lower")));
     $post->addTags($tags);
     if (!$success) {
         foreach ($post->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "posts", "action" => "new"));
     }
     $this->sendPings();
     $this->flash->success("post was created successfully");
     return $this->dispatcher->forward(array("controller" => "posts", "action" => "index"));
 }