Example #1
0
 protected function findModel($id)
 {
     if (($model = Article::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundException("The requested page does not exist");
     }
 }
Example #2
0
 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]);
 }
Example #3
0
 /**
  * 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;
     }
 }
Example #4
0
 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]);
 }
 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'));
 }
Example #6
0
 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']]);
     }
 }
Example #7
0
 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;
 }
 /**
  * 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.');
     }
 }
 /**
  * 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.');
     }
 }