/** * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function run($id) { $category = Category::findOne(['id' => $id]); if (!empty($category)) { $param = ['category' => $id]; $extraOptions = ['filterEnable' => true]; return $this->controller->renderIndex($param, $extraOptions); } else { $this->controller->redirect(['/transaction']); } }
public function actionCategory($link) { $category = Category::findOne(['fullLink' => $link]); if (!$category) { if ($redirect = Redirect::findOne(['from' => $link])) { return \Yii::$app->response->redirect(yii\helpers\Url::to($redirect->to, true), 301)->send(); } throw new NotFoundHttpException(); } if (!empty($category->parentCategory)) { $this->getView()->params['breadcrumbs'][] = ['label' => $category->parentCategory->title, 'url' => yii\helpers\Url::toRoute(['/' . $category->parentCategory->fullLink], true)]; } return $this->render('category', ['category' => $category, 'dataProvider' => new ActiveDataProvider(['query' => $category->getNews()->with('category'), 'sort' => ['defaultOrder' => ['publishDate' => SORT_DESC]], 'pagination' => ['pageSize' => 5]])]); }
/** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
</a> - in <b><?php echo $order->city; ?> </b> Added: <i><?php echo $formatedDate; ?> </i> </li> <?php } ?> </ul> <ul class="list-group"> <h1 class="page-header">Posts: <?php echo Category::findOne($_GET['category'])->name; ?> </h1> <?php foreach ($postOrders as $post) { ?> <?php $author = Author::getAuthor($post->author_id); ?> <li class="list-group-item"> Title: <a href="<?php echo Yii::$app->urlManager->createUrl(['posts/details', 'id' => $post->id]); ?> "><?php echo $post->title; ?>