当前位置: 首页>>代码示例>>PHP>>正文


PHP Posts::findFirst方法代码示例

本文整理汇总了PHP中Posts::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::findFirst方法的具体用法?PHP Posts::findFirst怎么用?PHP Posts::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Posts的用法示例。


在下文中一共展示了Posts::findFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addAction

 /**
  * Добавляет новую должность
  */
 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);
 }
开发者ID:sergeytkachenko,项目名称:angular-gulp-phalcon,代码行数:29,代码来源:PostsController.php

示例2: setAction

 public function setAction()
 {
     $post = ['name' => false, 'email' => false, 'comment' => true];
     if ($this->_status['response']['status'] && !$this->_getPost($post)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 201;
         $this->_status['response']['detail'] = $post['empty'];
     }
     $urlId = $this->dispatcher->getParam('id');
     if (!$this->_status['response']['status'] && empty($urlId)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 203;
     }
     $posts = Posts::findFirst($urlId);
     if ($this->_status['response']['status'] && !$posts) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 404;
     }
     if (!$this->_status['response']['status']) {
         return $this->response->setJsonContent($this->_status);
     }
     $comments = new Comments();
     $comments->assign(['posts_id' => $posts->id, 'name' => $this->_post['name'], 'email' => $this->_post['email'], 'comment' => $this->_post['comment']]);
     if (!$comments->save()) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 102;
     }
     return $this->response->setJsonContent($this->_status);
 }
开发者ID:gomasiyo,项目名称:cms,代码行数:29,代码来源:CommentController.php

示例3: showAction

 /**
  * Let’s read that record from the database. When using MySQL adapter,
  * like we do in this tutorial, $slug variable will be escaped so
  * we don’t have to deal with it.
  */
 public function showAction($slug)
 {
     $post = Posts::findFirst(array('slug = :slug:', 'bind' => array('slug' => $slug)));
     if ($post === false) {
         $this->flash->error("Sorry, post not found");
         $this->dispatcher->forward(array('controller' => 'posts', 'action' => 'index'));
     }
     $this->view->setVar('post', $post);
 }
开发者ID:alawnchen,项目名称:blog-tutorial,代码行数:14,代码来源:PostsController.php

示例4: postAction

 public function postAction($id)
 {
     $post = Posts::findFirst($id);
     if (!$post) {
         return (new \Phalcon\Http\Response())->setStatusCode(404, "Not Found")->setContent("Not Found");
     }
     $this->view->pick('posts/post');
     $this->view->title = $post->getTitle();
     $this->view->content = $post->getContent();
     $this->view->id = $id;
     //select all comments for the post
     $comments = PostComments::find(array('conditions' => 'post_id = ?1', 'bind' => array(1 => $id)));
     $comment_array = array();
     foreach ($comments as $c) {
         $comment = Comments::findFirst($c->getCommentId());
         array_push($comment_array, array('commenter' => $comment->getName(), 'content' => $comment->getContent()));
     }
     $this->view->comments = $comment_array;
 }
开发者ID:poorman,项目名称:MyCMS,代码行数:19,代码来源:PostsController.php

示例5: editAction

 public function editAction($id = 0)
 {
     $editForm = new AutoForm(\Posts::findFirst($id), 'save');
     $this->view->setVars(['testForm' => $editForm]);
 }
开发者ID:moaljazaery,项目名称:phalcon-module-admin,代码行数:5,代码来源:IndexController.php

示例6: articleAction

 public function articleAction()
 {
     $article_id = $this->dispatcher->getParam('id');
     $post = Posts::findFirst($article_id);
     if (!$post) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 404;
         return $this->response->setJsonContent($this->_status);
     }
     $content = preg_split('/\\[more\\]/', $post->content);
     $content = implode('', $content);
     $tags = Tags::findByPosts_id($post->id);
     $tag_array = [];
     if ($tags) {
         foreach ($tags as $tag) {
             $tag_array[] = $tag->tag;
         }
     }
     $categories = Categories::findByPosts_id($post->id);
     $category_array = [];
     if ($categories) {
         foreach ($categories as $category) {
             $category_array[] = $category->category;
         }
     }
     $comments = Comments::findByPosts_id($post->id);
     $comment_array = [];
     if ($comments) {
         foreach ($comments as $comment) {
             $array = [];
             $array['name'] = $comment->name;
             $array['email'] = $comment->email;
             $array['comment'] = $comment->comment;
             $comment_array[] = $array;
         }
     }
     $this->_status['response']['entry'] = ['id' => $post->id, 'author' => $post->users->name, 'title' => $post->title, 'content' => $content, 'tags' => $tag_array, 'categories' => $category_array, 'comments' => $comment_array];
     return $this->response->setJsonContent($this->_status);
 }
开发者ID:gomasiyo,项目名称:cms,代码行数:39,代码来源:EntryController.php


注:本文中的Posts::findFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。