本文整理匯總了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]);
}
示例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.');
}
}
示例3: actionAddStars
public function actionAddStars($id)
{
if (\Yii::$app->request->isAjax) {
$model = Article::findOne($id);
$model->addStars();
return json_encode(1);
}
}
示例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.');
}
}
示例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]);
}
示例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';
}
}
示例7: deleteArticle
/**
* Deletes Article
* @throws \Exception
*/
public function deleteArticle()
{
/** @var $article Article */
if ($article = Article::findOne($this->item_id)) {
$article->removeAllTagValues();
$article->delete();
}
}
示例8: init
public function init()
{
parent::init();
$this->_article = Article::findOne($this->id);
}
示例9: findModel
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
// 跳轉到 :您訪問到頁麵不存在
}
}
示例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']);
}
}
}
}
示例11: findModel
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('您要訪問的頁麵不存在!');
}
}
示例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"
}