本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例5: editAction
public function editAction($id = 0)
{
$editForm = new AutoForm(\Posts::findFirst($id), 'save');
$this->view->setVars(['testForm' => $editForm]);
}
示例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);
}