public function getListByCategory($slug, $fields = [], $with = [], $page = false, $pageSize = false, $order = '') { $category = Category::getInstance()->getBySlug($slug); $model = self::$model->find()->select($fields)->where(['type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE, 'meta_id' => $category['id']])->join('RIGHT JOIN', Relationship::tableName() . ' relation', 'content_id=id'); $countModel = clone $model; $pagination = new Pagination(['totalCount' => $countModel->count(), 'pageSize' => $pageSize]); if ($page) { $pagination->setPage($page, true); } switch (strtoupper($order)) { case 'VIEW': $model->orderBy('view_total DESC'); break; case 'COMMENT': $model->orderBy('comment_total DESC'); break; case 'CREATED': $model->orderBy('created_at DESC'); break; case 'UPDATED': $model->orderBy('updated_at DESC'); break; } return ['data' => $model->with($with)->limit($pagination->getLimit())->offset($pagination->getOffset())->all(), 'pagination' => $pagination]; }
public function actionView($slug) { $articles = Article::getInstance()->getListByCategory($slug); $category = Category::getInstance()->getBySlug($slug); $hotArticles = Article::getInstance()->getHotListByCategory($slug, ['title', 'slug'], [], 1, 10); return $this->render('view', ['articles' => $articles, 'category' => $category, 'hotArticles' => $hotArticles]); }
var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?80ac0b001726544dba4e32f02b6c31c8"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </head> <body> <?php $this->beginBody(); ?> <div class="wrap"> <?php NavBar::begin(['brandLabel' => '<i class="glyphicon glyphicon-home"></i>', 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-default navbar-fixed-top']]); $menuLeftItems = []; if ($categorys = \common\helpers\Category::getInstance()->getTree(0, ['id', 'name', 'parent_id', 'slug'])) { foreach ($categorys as $category) { $item = ['label' => $category['name'], 'url' => ['/category/view', 'slug' => $category['slug']]]; if (!empty($category['_childs'])) { foreach ($category['_childs'] as $child) { $item['items'][] = ['label' => $child['name'], 'url' => ['/category/view', 'slug' => $child['slug']]]; } } $menuLeftItems[] = $item; } } if ($pages = \common\helpers\Page::getInstance()->getList(['id', 'title', 'slug'], [], 10, 1)['data']) { foreach ($pages as $page) { $menuLeftItems[] = ['label' => $page['title'], 'url' => ['/page/view', 'slug' => $page['slug']]]; } }
?> " class="list-group-item"><?php echo $article['title']; ?> </a> <?php } ?> </div> </div> <div class="panel panel-default"> <div class="panel-heading">魔法分类</div> <div class="list-group"> <?php foreach (\common\helpers\Category::getInstance()->getList()['data'] as $category) { ?> <a href="<?php echo \yii\helpers\Url::toRoute(['/category/view', 'slug' => $category['slug']]); ?> " class="list-group-item"><?php echo $category['name']; ?> </a> <?php } ?> </div> </div>
?> </div> </div> <div class="col-md-4"> <?php echo \kartik\tabs\TabsX::widget(['renderTabContent' => false, 'items' => [['label' => Yii::t('app', 'Options'), 'active' => true, 'options' => ['id' => 'options']], ['label' => Yii::t('app', 'Attachment'), 'options' => ['id' => 'attachments']]]]); ?> <div class="tab-content"> <div id="options" class="tab-pane active"> <?php echo $form->field($model, 'status')->radioList($model->getStatusOptions(), ['inline' => true]); ?> <?php echo $form->field($model, 'category')->widget(\kartik\widgets\Select2::className(), ['pluginOptions' => ['placeholder' => ' - 请选择分类 - '], 'data' => \yii\helpers\ArrayHelper::map(\common\helpers\Category::getInstance()->getAll(['id', 'name']), 'id', 'name')]); ?> <?php echo $form->field($model, 'tags')->widget(\dosamigos\selectize\SelectizeTextInput::className(), ['loadUrl' => ['/tag/index'], 'clientOptions' => ['placeholder' => '标签(可选)', 'allowEmptyOption' => false, 'valueField' => 'name', 'labelField' => 'name', 'searchField' => 'name', 'delimiter' => ',', 'maxItems' => 5, 'plugins' => ['remove_button'], 'persist' => false, 'create' => true], 'options' => ['value' => implode(',', \yii\helpers\ArrayHelper::getColumn($model->tags, 'name'))]]); ?> <?php echo $form->field($model, 'order')->textInput(['placeholder' => 'Enter Order...']); ?> <?php echo $form->field($model, 'password')->passwordInput(['placeholder' => 'Enter Password...']); ?> <?php