コード例 #1
0
ファイル: CategoryList.php プロジェクト: Penton/MoBlog
 public function init()
 {
     parent::init();
     $categories = CategoryTree::getInstance()->getAllCategories();
     $this->_htmlStr = '<ul>';
     if (!empty($categories)) {
         foreach ($categories as $v) {
             $this->_htmlStr .= '<li>';
             $this->_htmlStr .= str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $v['depth'] - 1) . Html::a($v['name'] . '(' . $v['count'] . ')', ['site/category', 'slug' => $v['slug']], $this->options);
             $this->_htmlStr .= '</li>';
         }
     }
     $this->_htmlStr .= '</ul>';
 }
コード例 #2
0
 public function init()
 {
     parent::init();
     $this->options['encodeSpaces'] = true;
     $postCategoryIds = [];
     if ($this->postId !== null) {
         $post = Post::find()->andwhere('cid=:cid', [':cid' => $this->postId])->one();
         $postCategories = $post->getCategories()->asArray()->all();
         $postCategoryIds = yii\helpers\ArrayHelper::getColumn($postCategories, 'mid');
     }
     $categories = CategoryTree::getInstance()->getAllCategories();
     $this->_inputStr = '<div class="form-group">';
     $this->_inputStr .= Html::label('分类');
     if (!empty($categories)) {
         foreach ($categories as $v) {
             $this->_inputStr .= '<div class="checkbox">';
             $this->_inputStr .= str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $v['depth'] - 1) . Html::checkbox('inputCategories[]', in_array($v['mid'], $postCategoryIds), ['label' => $v['name'], 'value' => $v['mid']]);
             $this->_inputStr .= '</div>';
         }
     }
     $this->_inputStr .= '</div>';
 }
コード例 #3
0
 public function init()
 {
     parent::init();
     $this->options['encodeSpaces'] = true;
     $this->options['prompt'] = '不选择';
     $categories = CategoryTree::getInstance()->getAllCategories();
     if (!empty($categories)) {
         foreach ($categories as $v) {
             $tempArr = [];
             $tempArr[$v['mid']] = str_repeat('    ', $v['depth'] - 1) . $v['name'];
             $this->_categories += $tempArr;
             if ($this->currentOptionDisabled) {
                 $model = $this->model;
                 $this->options['options'][$model->mid] = ['disabled' => true];
             }
         }
     }
     $this->_inputStr = '<div class="form-group">';
     $this->_inputStr .= Html::activeLabel($this->model, $this->attribute);
     $this->_inputStr .= Html::activeDropDownList($this->model, $this->attribute, $this->_categories, $this->options);
     $this->_inputStr .= '</div>';
 }
コード例 #4
0
ファイル: index.php プロジェクト: Penton/MoBlog
            <li><a href="#">删除</a></li>
            <li><a href="#">更新</a></li>
        </ul>

    </div>
        <?php 
echo Html::a('新增', ['create'], ['class' => 'btn btn-success']);
?>
    <?php 
if ($parentCategory) {
    ?>
        <?php 
    echo Html::a('返回上一级', ['/category', 'parent' => $parentCategory->parent], ['class' => 'btn btn-default']);
    ?>
    <?php 
}
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => \yii\grid\CheckboxColumn::className()], 'name', ['header' => '子分类', 'class' => yii\grid\Column::className(), 'content' => function ($model, $key, $index, $column) {
    $count = \common\components\CategoryTree::getInstance()->getSubCategoriesCount($model->mid);
    if ($count == 0) {
        return Html::a('新增', ['/category/create', 'parent' => $model->mid]);
    } else {
        return Html::a($count . '个分类', ['/category', 'parent' => $model->mid]);
    }
}], 'slug', 'count', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']], 'tableOptions' => ['class' => 'table table-striped']]);
?>

</div>