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


PHP Article::findOne方法代码示例

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


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

示例1: findModel

 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundException("The requested page does not exist");
     }
 }
开发者ID:irying,项目名称:artist,代码行数:8,代码来源:ArticleController.php

示例2: actionView

 public function actionView($id)
 {
     $counter = new counter();
     $counter->hitsCounter('site/view', $id);
     $model = Article::findOne(['id' => $id]);
     $article = new Article();
     return $this->render('view', ['model' => $model, 'article' => $article]);
 }
开发者ID:jatuponp,项目名称:discovery,代码行数:8,代码来源:SiteController.php

示例3: 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 string $id
  * @return Article the loaded model
  */
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         return false;
     }
 }
开发者ID:amarchenkov,项目名称:myCMS,代码行数:14,代码来源:ArticleUrlRule.php

示例4: actionShowwidget

 public function actionShowwidget($post)
 {
     $model = new Article();
     $ress = $model->findOne(['id' => $post])->toArray();
     // получаем статью детально ввиде массива
     //$CatRess = $model2->findOne(['id' => $ress['category_id']]); // Это я так баловался:)
     $CatRess = $model->LoadCat($ress['category_id']);
     //Загружаем из модели категорию с полученым ID, вытащить напрямую без указания не получилось
     return $this->render('views', ['modelcat' => $CatRess, 'model' => $ress]);
 }
开发者ID:proufa,项目名称:basic,代码行数:10,代码来源:ArticleController.php

示例5: actionDelete

 public function actionDelete($id = null)
 {
     if ($id === null) {
         Yii::$app->session->setFlash('PostDeletedError');
         Yii::$app->getResponse()->redirect(array('article/index'));
     }
     /** @var Article $article */
     $article = Article::findOne($id);
     if ($article === null) {
         Yii::$app->session->setFlash('PostDeletedError');
         Yii::$app->getResponse()->redirect(array('article/index'));
     }
     $article->delete();
     Yii::$app->session->setFlash('PostDeleted');
     Yii::$app->getResponse()->redirect(array('article/index'));
 }
开发者ID:Cherkesov,项目名称:hello-yii2,代码行数:16,代码来源:ArticleController.php

示例6: order

 private function order($id = null, $ordering = null, $direction = null)
 {
     if ($id != null || $ordering != null || $direction != null) {
         $sess = Yii::$app->session->get('sessArticle');
         if ($direction == "up") {
             $newSortOrder = $ordering - 1;
         } else {
             if ($direction == "down") {
                 $newSortOrder = $ordering + 1;
             }
         }
         $parent = Article::findOne($id);
         $where = array();
         $where[] = "ordering = '{$newSortOrder}'";
         $where[] = "langs = '" . $parent->langs . "'";
         $where[] = "cid = '" . $parent->cid . "'";
         $connection = Yii::$app->db;
         $sql = "SELECT id FROM tbl_article " . (count($where) ? "\n WHERE " . implode(' AND ', $where) : '');
         $command = $connection->createCommand($sql);
         $reader = $command->query();
         foreach ($reader as $row) {
             $otherId = $row["id"];
         }
         $where = array();
         $where[] = "id = '{$id}'";
         $where[] = "langs = '" . $parent->langs . "'";
         $where[] = "cid = '" . $parent->cid . "'";
         $sql = 'UPDATE tbl_article SET ordering = "' . $newSortOrder . '" ' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : '');
         $command = $connection->createCommand($sql);
         $command->execute();
         if ($reader->getRowCount() > 0) {
             $where = array();
             $where[] = "id = '{$otherId}'";
             $where[] = "langs = '" . $parent->langs . "'";
             $where[] = "cid = '" . $parent->cid . "'";
             $sql = 'UPDATE tbl_article SET ordering = "' . $ordering . '"' . (count($where) ? "\n WHERE " . implode(' AND ', $where) : '');
             $command = $connection->createCommand($sql);
             $command->execute();
         }
         return $this->redirect(['index', 'page' => $_REQUEST['page']]);
     }
 }
开发者ID:jatuponp,项目名称:rgweb,代码行数:42,代码来源:ArticleController.php

示例7: checkOwner

 public function checkOwner($id)
 {
     $auth = \Yii::$app->authManager->getAssignments(\Yii::$app->user->id);
     //print_r($auth);
     $access = false;
     if ($auth['Editor']->roleName == 'Editor') {
         $model = Article::findOne($id);
         if ($model->createBy == \Yii::$app->user->id) {
             $access = true;
         }
     } else {
         $access = true;
     }
     return $access;
 }
开发者ID:jatuponp,项目名称:iweb,代码行数:15,代码来源:Article.php

示例8: 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 {
         $this->layout = 'admin';
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:samatic,项目名称:yii2-starter,代码行数:16,代码来源:ArticleController.php

示例9: 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
  */
 public static function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:AhmedMH,项目名称:news-portal,代码行数:15,代码来源:ArticleController.php


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