當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Article::findOne方法代碼示例

本文整理匯總了PHP中common\models\Article::findOne方法的典型用法代碼示例。如果您正苦於以下問題:PHP Article::findOne方法的具體用法?PHP Article::findOne怎麽用?PHP Article::findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\Article的用法示例。


在下文中一共展示了Article::findOne方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionView

 public function actionView($id)
 {
     $article = Article::findOne($id);
     $comment = new Comment();
     $comments = $article->comments;
     return $this->render("view", ["article" => $article, "comment" => $comment, "comments" => $comments]);
 }
開發者ID:horechek,項目名稱:nnews,代碼行數:7,代碼來源:ArticleController.php

示例2: findModel

 /**
  * Finds the Article model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Article the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
開發者ID:Brother-Simon,項目名稱:yii2-starter-kit,代碼行數:15,代碼來源:ArticleController.php

示例3: actionAddStars

 public function actionAddStars($id)
 {
     if (\Yii::$app->request->isAjax) {
         $model = Article::findOne($id);
         $model->addStars();
         return json_encode(1);
     }
 }
開發者ID:buuug7,項目名稱:game4039,代碼行數:8,代碼來源:ArticleController.php

示例4: findModel

 /**
  * Finds the ArticleDownload model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ArticleDownload the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $ArticleDownload = ArticleDownload::findOne($id);
     $Article = Article::findOne($id);
     if ($ArticleDownload !== null && $Article !== null) {
         return ['ArticleDownload' => $ArticleDownload, 'Article' => $Article];
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
開發者ID:wordnews,項目名稱:wei_shop,代碼行數:17,代碼來源:DownloadController.php

示例5: actionDetail

 public function actionDetail($id)
 {
     if (!($article = Article::findOne($id))) {
         throw new NotFoundHttpException('ID 為 ' . $id . ' 的文章沒有找到');
     }
     //文章標簽
     $tags = $article->getArticleTag();
     //相關文章
     return $this->render('detail', ['article' => $article, 'tags' => $tags]);
 }
開發者ID:specialnote,項目名稱:myYii,代碼行數:10,代碼來源:ArticleController.php

示例6: init

 public function init()
 {
     parent::init();
     if ($this->id) {
         $this->_item = Article::findOne($this->id);
     } else {
         throw new InvalidParamException(\Yii::t('front', 'No required parameter given') . ' - id');
     }
     if (!$this->articleType) {
         $this->articleType = 'normal';
     }
 }
開發者ID:czechcamus,項目名稱:dasport,代碼行數:12,代碼來源:NewsletterArticle.php

示例7: deleteArticle

 /**
  * Deletes Article
  * @throws \Exception
  */
 public function deleteArticle()
 {
     /** @var $article Article */
     if ($article = Article::findOne($this->item_id)) {
         $article->removeAllTagValues();
         $article->delete();
     }
 }
開發者ID:czechcamus,項目名稱:dasport,代碼行數:12,代碼來源:ArticleForm.php

示例8: init

 public function init()
 {
     parent::init();
     $this->_article = Article::findOne($this->id);
 }
開發者ID:czechcamus,項目名稱:dasport,代碼行數:5,代碼來源:NewsletterArticle.php

示例9: findModel

 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         // 跳轉到 :您訪問到頁麵不存在
     }
 }
開發者ID:codekissyoung,項目名稱:filmfest,代碼行數:8,代碼來源:ArticleController.php

示例10: actionArtedit

 public function actionArtedit()
 {
     if (Yii::$app->request->get('id')) {
         $id = Yii::$app->request->get('id');
         $cate = ArticleCate::find()->all();
         //類別數據填充
         $model = Article::findOne($id);
         return $this->render('artedit', ['id' => $id, 'cate' => $cate, 'model' => $model]);
     } elseif (Yii::$app->request->post('id')) {
         $id = Yii::$app->request->post('id');
         $model = Article::findOne($id);
         $cover = $model->cover;
         if ($model === null) {
             Yii::$app->getSession()->setFlash("info", '編輯失敗');
             return $this->redirect(['articlelist']);
         }
         if ($model->load(Yii::$app->request->post())) {
             if ($_FILES['Article']['name']['cover']) {
                 //刪除原圖片
                 if ($cover) {
                     unlink($cover);
                 }
                 //更新新圖片
                 $img = Yii::$app->imgload->UploadPhoto($model, 'uploads/article/', 'cover');
                 $model->cover = $img;
             } else {
                 $model->cover = $cover;
             }
             if ($model->save()) {
                 Yii::$app->getSession()->setFlash('info', '編輯成功!');
                 return $this->redirect(['articlelist']);
             } else {
                 Yii::$app->getSession()->setFlash('info', '編輯失敗!');
                 @unlink($img);
                 return $this->redirect(['articlelist']);
             }
         }
     }
 }
開發者ID:dlpc,項目名稱:yii2-plane,代碼行數:39,代碼來源:ArticleController.php

示例11: findModel

 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('您要訪問的頁麵不存在!');
     }
 }
開發者ID:codekissyoung,項目名稱:filmfest,代碼行數:8,代碼來源:VideoController.php

示例12: closed

    echo Article::findOne(['id' => $model['recommend2_id']])->title;
    ?>
</p>
      </a></li>
  <?php 
}
?>
  <?php 
if (!empty($model['recommend3_id'])) {
    ?>
    <li><a href="<?php 
    echo \yii\helpers\Url::toRoute('/article/' . $model['recommend3_id'] . '-' . \Yii::$app->user->id);
    ?>
">
      <p><?php 
    echo Article::findOne(['id' => $model['recommend3_id']])->title;
    ?>
</p>
      </a></li>
  <?php 
}
?>
  </ul>
</div>
<div class="wycs"></div>
<script>
function closed()
{
 var aaa=document.getElementById("ad");
 aaa.style.display="none"
}
開發者ID:Brother-Simon,項目名稱:yii2-starter-kit,代碼行數:31,代碼來源:index.php


注:本文中的common\models\Article::findOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。