Esempio n. 1
0
 /**
  * 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 ($id !== null && ($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('请求页面不存在');
     }
 }
Esempio n. 2
0
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['sort_order' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition($query, 'id');
     $this->addCondition($query, 'name', true);
     $this->addCondition($query, 'sort_order');
     $this->addCondition($query, 'created_at');
     $this->addCondition($query, 'updated_at');
     $this->addCondition($query, 'deleted_at');
     return $dataProvider;
 }
Esempio n. 3
0
<?php

use app\widgets\Sidebar;
use app\models\ar\Category;
$this->beginContent('@app/views/layouts/main.php');
include "_nav.php";
?>

    <div class="container" style="margin-top:5em; padding-bottom:1em;">
        <div class="row row-offcanvas row-offcanvas-right">
            <?php 
echo $content;
?>
            <?php 
$categories_array = [['categoryId' => 0, 'label' => '所有分类', 'url' => ['/site/index']]];
$categories = Category::getCategories();
foreach ($categories as $category) {
    $categories_array[] = ['categoryId' => $category['id'], 'label' => $category['name'], 'url' => ['site/index', 'category_id' => $category['id']]];
}
echo Sidebar::widget(['title' => '文章分类', 'items' => $categories_array, 'handleActive' => function ($id) {
    $currentId = 0;
    if (isset($_GET['category_id'])) {
        $currentId = intval($_GET['category_id']);
    }
    return $currentId == $id;
}]);
?>
        </div>
    </div>
<?php 
$this->endContent();