public function actionView($slug) { $commentForm = new Comment(); if ($commentForm->load(Yii::$app->request->post())) { if ($commentForm->save()) { Yii::$app->session->setFlash('success', '评论发表成功'); } else { Yii::$app->session->setFlash('error', '评论发表失败'); } } return $this->render('view', ['article' => Page::getInstance()->getBySlug($slug), 'commentForm' => $commentForm]); }
<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']]]; } } $menuRightItems = []; if (Yii::$app->user->isGuest) { // $menuRightItems[] = ['label' => 'Signup', 'url' => ['/site/signup']]; $menuRightItems[] = ['label' => 'Login', 'url' => ['/site/login']]; } else { $menuRightItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->nickname . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']]; } echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-left'], 'activateParents' => true, 'items' => $menuLeftItems]); echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuRightItems]); NavBar::end(); ?>