/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'root' => $this->root, 'lft' => $this->lft, 'rgt' => $this->rgt, 'pid' => $this->pid, 'level' => $this->level, 'if_show' => $this->if_show, 'sort' => $this->sort]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'pic', $this->pic])->andFilterWhere(['like', 'position', $this->position])->andFilterWhere(['like', 'memo', $this->memo]);
     return $dataProvider;
 }
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #3
0
use source\LsYii;
use common\widgets\TreeView;
use source\modules\category\models\Category;
/* @var $this yii\web\View */
/* @var $searchModel source\models\search\MenuSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '分类管理';
$this->registerJs("\$(function(){\n    \$('.nav-tabs .active').mouseover(function(){\n        \$(this).find('.attribute-remove').show();\n    }).mouseout(function(){\n        \$(this).find('.attribute-remove').hide();\n    });\n    \$('.nav-tabs .active .attribute-remove').click(function(){\n        window.open('" . \source\helpers\Url::to(['/category/default/delete', 'id' => $model->id]) . "' , '_self');\n        return false;\n    });\n})", \source\core\back\BackView::POS_END);
echo source\libs\Message::getMessage();
?>
<div class="page-header">
    <h3>
        <strong><?php 
echo Html::encode($this->title);
?>
</strong>
        <div class="pull-right">
            <?php 
echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . LsYii::gT('添加新分类'), ['/category/default/create'], ['class' => 'btn btn-primary']);
?>
        </div>
    </h3>
</div>
<div class="menu-index">
    <?php 
echo yii\bootstrap\Tabs::widget(['items' => Category::getItems($model->id, '/category/default/index')]);
echo TreeView::widget(['data' => Category::getTreeData($model->root, $model->id, true, false, ['updateUrl' => '/category/default/update', 'addChildrenUrl' => '/category/default/create', 'deleteUrl' => '/category/default/delete'])]);
?>

</div>
Exemple #4
0
/* @var $this yii\web\View */
/* @var $model source\models\Category */
/* @var $form yii\widgets\ActiveForm */
$this->registerJsFile(Resource::getAdminUrl('/default/js/bootstrap-smartsearch.js'), ['depends' => 'yii\\web\\YiiAsset']);
?>

<div class="category-form">

    <?php 
$form = ActiveForm::begin(['id' => 'category-form', 'options' => ['class' => 'form-horizontal']]);
?>
    <?php 
$disabeld = $model->isNewRecord ? false : true;
?>
    <?php 
echo $form->field($model, 'pid')->textInput(['class' => 'form-control', 'autocomplete' => 'off', 'data-provide' => "smartsearch", 'data-items' => "all", 'data-source' => Category::getToJson(), 'data-value' => $model->pid, 'disabled' => $disabeld]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'url')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'if_show')->radioList(Constants::getCategoryStatus());
?>

    <?php