/**
  * Updates an existing Category model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $category_array = Category::getAllCategories();
     $category_array = ['0' => '顶级分类'] + $category_array;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $id]);
     } else {
         return $this->render('update', ['model' => $model, 'category_array' => $category_array]);
     }
 }
Example #2
0
 */
use yii\web\View;
use yii\helpers\Url;
use yii\data\ActiveDataProvider;
use yii\widgets\LinkPager;
use app\models\Post;
use app\models\Category;
/* @var View $this */
/* @var Post $posts */
/* @var string $tag */
/* @var ActiveDataProvider $dataProvider */
$this->params['breadcrumbs'] = [['label' => '所有标签', 'url' => Url::to(['tag/list'])], '标签'];
$sum = $dataProvider->totalCount;
$this->title = '标签:' . $tag;
$seo_description = "标签:{$tag}。该标签下共有{$sum}篇文章,";
$categories = Category::getAllCategories();
$post_names = array();
echo <<<HTML5
<header class="tag-info list-header">
    <h1><em class="glyphicon glyphicon-tag"></em>{$tag}  <small>共 {$sum} 篇</small></h1>
</header>
HTML5;
$posts = $dataProvider->models;
foreach ($posts as $post) {
    echo $this->render('/post/_article', array('post' => $post, 'category' => $categories[$post->cid]));
    $post_names[] = $post->title;
}
echo LinkPager::widget(['pagination' => $dataProvider->pagination]);
if (empty($this->params['seo_keywords'])) {
    $this->params['seo_keywords'] = $tag;
} else {
Example #3
0
echo $form->field($model, 'alias')->textInput(['maxlength' => true]);
?>
        </div>
        <div class="col-md-12 col-lg-4">
            <?php 
echo $form->field($model, 'author_name')->textInput(['maxlength' => true]);
?>
        </div>
    </div>
    <?php 
echo $form->field($model, 'cover', ['template' => '{label}<div class="input-group"><span class="input-group-btn"><button id="cover-upload" type="button" class="btn btn-success">上传图片</button></span>{input}</div>'])->textInput(['maxlength' => true]);
?>
    <div class="row">
        <div class="col-md-12 col-lg-3">
            <?php 
echo $form->field($model, 'cid')->dropDownList(Category::getAllCategories());
?>
        </div>
        <div class="col-md-12 col-lg-3">
            <?php 
echo $form->field($model, 'status')->dropDownList(Post::getAvailableStatus());
?>
        </div>
        <div class="col-md-12 col-lg-3">
            <?php 
echo $form->field($model, 'type')->dropDownList(Post::getAvailableType());
?>
        </div>
        <div class="col-md-12 col-lg-3">
            <?php 
echo $form->field($model, 'is_top')->dropDownList(['0' => '普通', '1' => '置顶']);
Example #4
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Category;
use app\models\Post;
/* @var $this yii\web\View */
/* @var $searchModel app\models\PostSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '文章管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="box post-index">
    <div class="box-header with-border">
        <?php 
echo Html::a('发表新文章', ['create'], ['class' => 'btn btn-success']);
?>
    </div>
    <div class="box-body">
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions' => ['class' => 'table table-bordered table-hover'], 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'title', ['attribute' => 'cid', 'value' => 'postCategory', 'filter' => Html::activeDropDownList($searchModel, 'cid', ['' => '全部'] + Category::getAllCategories(), ['class' => 'form-control'])], ['attribute' => 'author_id', 'value' => function ($model, $key, $index, $column) {
    return $model->author ? $model->author->nickname : null;
}], ['attribute' => 'is_top', 'format' => 'html', 'value' => function ($model, $key, $index, $column) {
    return $model->is_top ? '<span class="label label-success">置顶</span>' : '';
}, 'filter' => Html::activeDropDownList($searchModel, 'is_top', ['' => '全部', '0' => '否', '1' => '是'], ['class' => 'form-control'])], ['attribute' => 'status', 'value' => 'postStatus', 'filter' => Html::activeDropDownList($searchModel, 'status', ['' => '全部'] + Post::getAvailableStatus(), ['class' => 'form-control'])], ['attribute' => 'comment_count', 'filter' => false], ['attribute' => 'view_count', 'filter' => false], ['attribute' => 'post_time', 'format' => ['date', 'php:Y-m-d H:i:s'], 'filter' => false], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}&nbsp;&nbsp;{update}']]]);
?>
    </div>
</div>
Example #5
0
 /**
  * 获得文章所属分类
  * @return string|null
  */
 public function getPostCategory()
 {
     $categories = Category::getAllCategories();
     return isset($categories[$this->cid]) ? $categories[$this->cid] : null;
 }