/**
  * 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('The requested page does not exist.');
     }
 }
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     //        $this->addCondition($query, 'id');
     //        $this->addCondition($query, 'root');
     //        $this->addCondition($query, 'lft');
     //        $this->addCondition($query, 'rgt');
     //        $this->addCondition($query, 'level');
     //        $this->addCondition($query, 'title', true);
     //        $this->addCondition($query, 'description', true);
     return $dataProvider;
 }
Esempio n. 3
0
echo $form->field($model, 'title', ['options' => ['maxlength' => 255], 'addon' => ['prepend' => ['content' => '<i class="glyphicon glyphicon-star"></i>']]]);
?>
            <?php 
echo $form->field($model, 'description')->widget(\zxbodya\yii2\tinymce\TinyMce::className(), ['language' => 'ru', 'settings' => ['image_class_list' => [['title' => 'responsive', 'value' => 'img-responsive'], ['title' => 'none', 'value' => '']], 'rel_list' => [[title => 'FancyBox', value => 'fancybox'], [title => 'Обычная', value => '']], 'force_br_newlines' => true, 'force_p_newlines' => false, 'forced_root_block' => false, 'height' => 200, 'image_dimensions' => false, 'extended_valid_elements' => 'img[*],div[*]'], 'fileManager' => ['class' => \zxbodya\yii2\elfinder\TinyMceElFinder::className(), 'connectorRoute' => '/blog/el-finder/connector'], 'spellcheckerUrl' => 'http://speller.yandex.net/services/tinyspell']);
?>
        </div>
        <div class="col-xs-3">
            <?php 
echo $form->field($model, 'status')->dropDownList(Blog::statusOptions());
?>
            <label><?php 
echo \Yii::t('blog', 'Category');
?>
</label>
            <?php 
echo TreeViewInput::widget(['query' => Category::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Категория'], 'attribute' => 'category_id', 'model' => $model, 'asDropdown' => true, 'multiple' => false, 'fontAwesome' => true, 'rootOptions' => ['label' => '<i class="fa fa-tree"></i>', 'class' => 'text-success']]);
?>
            <?php 
echo $form->field($model, 'tagged');
?>
            <div class="form-group">
                <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('blog', 'Create') : Yii::t('blog', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
            </div>
        </div>
    </div>
    <?php 
echo $form->field($model, 'body')->widget(\zxbodya\yii2\tinymce\TinyMce::className(), ['language' => 'ru', 'settings' => ['image_class_list' => [['title' => 'responsive', 'value' => 'img-responsive'], ['title' => 'none', 'value' => '']], 'rel_list' => [[title => 'FancyBox', value => 'fancybox'], [title => 'Обычная', value => '']], 'force_br_newlines' => true, 'force_p_newlines' => false, 'forced_root_block' => false, 'height' => 500, 'image_dimensions' => false, 'extended_valid_elements' => 'img[*],div[*]'], 'fileManager' => ['class' => \zxbodya\yii2\elfinder\TinyMceElFinder::className(), 'connectorRoute' => '/blog/el-finder/connector'], 'spellcheckerUrl' => 'http://speller.yandex.net/services/tinyspell']);
?>
use besnovatyj\blog\models\Category;
use kartik\tree\TreeView;
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var besnovatyj\blog\models\CategorySearch $searchModel
 */
$this->title = Yii::t('blog', 'Categories');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-index">


    <?php 
if (Yii::$app->user->can('administrator')) {
    echo '<div class="alert alert-danger">Внимание!<br />У вас привилегии администратора, будьте осторожны при изменении и удалении любой информации на этой странице!</div>';
}
?>


    <h4><?php 
echo Html::encode($this->title);
?>
</h4>
    <?php 
echo TreeView::widget(['query' => Category::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Категории'], 'isAdmin' => false, 'softDelete' => !Yii::$app->user->can('administrator')]);
?>
</div>


Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }