本文整理汇总了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"
}