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


PHP Post::findOne方法代码示例

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


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

示例1: testSetTags

 public function testSetTags()
 {
     $sourceTags = [1, 3];
     $post = $this->postModel->findOne(2);
     $post->setTags($sourceTags);
     $this->assertInstanceOf('common\\models\\Post', $post);
     $this->assertTrue($post->save(false));
     $this->assertEquals($sourceTags, $post->getTags());
 }
开发者ID:richardcj,项目名称:Blog-Yii2,代码行数:9,代码来源:PostTest.php

示例2: findModel

 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('您所请求的页面不存在');
     }
 }
开发者ID:whystic,项目名称:yii2-whystic-blog,代码行数:15,代码来源:HomeController.php

示例3: findModel

 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:kibercoder,项目名称:bilious-octo-fibula,代码行数:8,代码来源:PostController.php

示例4: actionDeletePost

 public function actionDeletePost($id)
 {
     $post = Post::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if (!empty($post->id)) {
         return $post->delete();
     }
     return 'Not found post';
 }
开发者ID:bolom009,项目名称:testwork_api,代码行数:8,代码来源:PostController.php

示例5: getModel

 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $slug
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function getModel($slug)
 {
     if (($model = Post::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
     }
 }
开发者ID:lav45,项目名称:yii2-translated-behavior-demo,代码行数:15,代码来源:SiteController.php

示例6: getPost

 public function getPost($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Стать не найдена.');
     }
 }
开发者ID:obepyc,项目名称:yii2-news,代码行数:8,代码来源:Post.php

示例7: actionView

 public function actionView($id)
 {
     $post = Post::findOne($id);
     if (!$post) {
         throw new \yii\web\HttpException(400, 'Wrong post id', 405);
     }
     return $this->render('view', ['post' => $post]);
 }
开发者ID:VitaliyProdan,项目名称:hr,代码行数:8,代码来源:PostsController.php

示例8: getCategory

 public function getCategory()
 {
     $post = Post::findOne($this->id);
     foreach (explode(',', $post->category_id) as $value) {
         $category = Category::findOne($value);
         $data[] = ['id' => $category->id, 'parent_id' => $category->parent_id, 'title' => $category->title, 'indent' => $this->getIndent($category->indent)];
     }
     return $data;
 }
开发者ID:huynhtuvinh87,项目名称:cms,代码行数:9,代码来源:Post.php

示例9: actionCreate

 /**
  * Creates a new Comment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionCreate()
 {
     $model = new Comment();
     if (Yii::$app->request->isGet) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $model->author_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['../post/view', 'id' => $model->post_id]);
     } else {
         return $this->render('../post/view', ['model' => Post::findOne($model->post_id)]);
     }
 }
开发者ID:viktornord,项目名称:gh-php-blog,代码行数:19,代码来源:CommentController.php

示例10: actionView

 public function actionView($slug)
 {
     $post = Post::findOne(['slug' => $slug]);
     $comment = new Comment();
     $comment->name = '';
     $comment->email = '';
     $comment->body = '';
     if ($comment->load(Yii::$app->request->post())) {
         $comment->status = 0;
         if ($comment->save()) {
             Yii::$app->session->setFlash('success', ['type' => 'success', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'You\'re comment successfully stored and will shown after approval.', 'title' => 'Saving Comment']);
         } else {
             Yii::$app->session->setFlash('error', ['type' => 'danger', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'Sorry but we couldn\'t store your comment.', 'title' => 'Saving Comment']);
         }
     }
     return $this->render('view', ['post' => $post, 'comment' => $comment]);
 }
开发者ID:ninjacto,项目名称:ninjacto.com,代码行数:17,代码来源:BlogController.php

示例11: actionCreate

 public function actionCreate($id = null)
 {
     if ($id === null) {
         $post = new Post();
     } else {
         if (($post = Post::findOne(['id' => $id, 'author_id' => Yii::$app->getUser()->getId()])) === null) {
             throw new HttpException(404, 'Cannot find the requested post.');
         }
     }
     if (Yii::$app->getRequest()->getIsAjax() && $post->load(Yii::$app->getRequest()->post())) {
         Yii::$app->getResponse()->format = Response::FORMAT_JSON;
         return ActiveForm::validate($post);
     }
     if ($post->load(Yii::$app->getRequest()->post()) && $post->save()) {
         return $this->redirect(Post::findOne($id)->getUrl());
     }
     $rootSections = Section::find()->roots()->orderBy('title')->all();
     $mainSections = $post->rootSectionId === null ? [] : Section::find()->where(['section_id' => $post->rootSectionId])->orderBy('title')->all();
     return $this->render('create', ['post' => $post, 'rootSections' => $rootSections, 'mainSections' => $mainSections]);
 }
开发者ID:resurtm,项目名称:forum,代码行数:20,代码来源:PostController.php

示例12: testComment

 /**
  * @param AcceptanceTester $I
  */
 public function testComment(AcceptanceTester $I)
 {
     $I->wantTo('ensure that post comment works');
     $postView = PostViewPage::openBy($I);
     // $I->see('Sample Post', 'h1');
     $I->see('Sample Post');
     $I->amGoingTo('submit post comment form with no data');
     $postView->submitComment([]);
     $I->expectTo('see validations error');
     $I->see('Name cannot be blank.', '.help-block');
     $I->see('Email cannot be blank.', '.help-block');
     $I->see('Content cannot be blank.', '.help-block');
     $I->amGoingTo('submit post comment form with no correct email');
     $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => 'tester.email', 'comment_content' => 'New comment']);
     $I->expectTo('see that email is not correct');
     $I->see('Email is not a valid email address.');
     $I->dontSee('Name cannot be blank.', '.help-block');
     $I->dontSee('Content cannot be blank.', '.help-block');
     $I->amGoingTo('submit post comment form with correct data');
     $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => 'tester@writesdown.dev', 'comment_content' => 'New comment']);
     $I->expect('new comment saved');
     $I->dontSee('Name cannot be blank.', '.help-block');
     $I->dontSee('Email cannot be blank.', '.help-block');
     $I->dontSee('Content cannot be blank.', '.help-block');
     PostComment::deleteAll(['comment_author' => 'tester']);
     Post::findOne(1)->updateAttributes(['post_comment_count' => '1']);
 }
开发者ID:hdushku,项目名称:app-cms,代码行数:30,代码来源:PostCest.php

示例13: outCommentsTree

    /**
     * Output tree of comments
     * @param array $comments Array of Comment
     * @param int $parent_id 
     * @param array $options 
     */
    public static function outCommentsTree($comments, $parent_id, $options)
    {
        if (!isset($options) || !is_object($options)) {
            $showReplies = isset($options['showReplies']) ? $options['showReplies'] : true;
            $showReplyButton = isset($options['showReplyButton']) ? $options['showReplyButton'] : true;
            $postID = isset($options['postID']) ? $options['postID'] : false;
            $options = (object) compact('showReplies', 'showReplyButton', 'postID');
        }
        if (isset($comments[$parent_id])) {
            foreach ($comments[$parent_id] as $comment) {
                if (is_null($comment->user)) {
                    $username = 'Аноним';
                    $avatar = new Asset();
                    $avatar->assetable_type = Asset::ASSETABLE_USER;
                    $imageUrl = $avatar->getDefaultFileUrl();
                    $userUrl = false;
                } else {
                    $username = $comment->user->getDisplayName();
                    $avatar = $comment->user->getAsset();
                    $imageUrl = $avatar->getFileUrl();
                    $userUrl = $comment->user->getUrl();
                }
                $commentDate = Yii::$app->formatter->asDate(strtotime($comment->created_at), 'd MMMM Y HH:mm');
                $repliesCommentsCount = isset($comments[$comment->id]) ? count($comments[$comment->id]) : 0;
                $classRepliesCount = $repliesCommentsCount == 0 ? 'no-replies' : '';
                $textRepliesCount = $repliesCommentsCount == 0 ? '' : $repliesCommentsCount;
                $isReply = $parent_id == 0 ? false : true;
                $own = isset(Yii::$app->user->id) && Yii::$app->user->id == $comment->user_id ? 'yes' : 'no';
                $rating = $comment->getRating();
                $ratingUpClass = '';
                $ratingDownClass = '';
                if (!Yii::$app->user->isGuest && Yii::$app->user->id != $comment->user_id) {
                    $userRating = $comment->getUserVote();
                    if ($userRating == 1) {
                        $ratingUpClass = 'voted';
                    } elseif ($userRating == -1) {
                        $ratingDownClass = 'voted';
                    }
                } else {
                    $ratingUpClass = 'disable';
                    $ratingDownClass = 'disable';
                }
                $commentLevelClass = $parent_id == 0 ? 'lvl-one' : '';
                if ($parent_id == 0 && $options->postID && $comment->getCommentableType() == Comment::COMMENTABLE_POST) {
                    $post = Post::findOne($comment->commentable_id);
                    if (isset($post->id) && $post->id !== $options->postID) {
                        $options->postID = $post->id;
                        ?>
                        <div class="comment-theme">
                            <div class="theme-label">Комментарии по теме:</div>
                            <div class="theme-link">
                                <a href="<?php 
                        echo $post->getUrl();
                        ?>
" data-pjax="0"><?php 
                        echo $post->title;
                        ?>
</a>
                            </div>
                        </div>
                        <?php 
                    }
                }
                $adminLink = '';
                if (Yii::$app->user->can('admin')) {
                    $adminLink = '<a class="admin-view-link" target="_blank" href="/admin/comment/' . $comment->id . '" data-pjax="0"></a>';
                }
                ?>
                <div id="comment-<?php 
                echo $comment->id;
                ?>
" class="comment <?php 
                echo $commentLevelClass;
                ?>
" 
                    data-own="<?php 
                echo $own;
                ?>
"
                    data-comment-id="<?php 
                echo $comment->id;
                ?>
"
                    data-commentable-type="<?php 
                echo $comment->getCommentableType();
                ?>
"
                    data-commentable-id="<?php 
                echo $comment->commentable_id;
                ?>
" >
                    <div class="comment-user">
                        <div class="user-photo">
                            <?php 
//.........这里部分代码省略.........
开发者ID:alexsynytskiy,项目名称:Dynamomania,代码行数:101,代码来源:Comment.php

示例14: actionEditPost

 public function actionEditPost($id)
 {
     if (!YiiForum::checkAuth('post_edit')) {
         return $this->noPermission();
     }
     YiiForum::checkIsGuest();
     $boardId = YiiForum::getGetValue('boardid');
     $model = Post::findOne(['id' => $id]);
     $data = YiiForum::getPostValue('Post');
     if ($data == null) {
         $thread = Thread::findOne(['id' => $model['thread_id']]);
         $locals = [];
         $locals['thread'] = $thread;
         $locals['currentBoard'] = $this->getBoard($boardId);
         $locals['model'] = $model;
         return $this->render('edit-post', $locals);
     } else {
         $model->load(Yii::$app->request->post());
         $model->modify_time = TTimeHelper::getCurrentTime();
         $model->save();
         return $this->redirect(['view', 'id' => $model->thread_id]);
     }
 }
开发者ID:liasica,项目名称:yiiforum,代码行数:23,代码来源:ThreadController.php

示例15: actionPopup

 /**
  * Render file browser for editor and file input
  *
  * @param int|null $post_id
  * @param bool     $editor
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionPopup($post_id = null, $editor = false)
 {
     $this->layout = "blank";
     $model = new Media(['scenario' => 'upload']);
     if ($post_id) {
         if ($post = Post::findOne($post_id)) {
             return $this->render('popup', ['post' => $post, 'model' => $model, 'editor' => $editor]);
         } else {
             throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
         }
     }
     return $this->render('popup', ['model' => $model, 'editor' => $editor]);
 }
开发者ID:pramana08,项目名称:app-cms,代码行数:22,代码来源:MediaController.php


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