Beispiel #1
0
 /**
  * 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, 'sort' => ['defaultOrder' => ['left' => SORT_ASC]]]);
     $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, 'left' => $this->left, 'right' => $this->right, 'level' => $this->level]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * Deletes an existing Category model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $currentNode = $this->findModel($id);
     if (!$currentNode) {
         throw new NotFoundHttpException(Module::t('general', 'The category not found.'));
     }
     $node = Category::find()->select('id')->where(['and', ['>=', 'left', $currentNode->left], ['<=', 'right', $currentNode->right]])->asArray()->all();
     try {
         $currentNode->deleteNode();
         //            if($delcategory) {
         Post::deleteAll(['IN', 'category_id', ArrayHelper::getColumn($node, 'id')]);
         \Yii::$app->session->setFlash('success', Module::t('general', 'Delete category successfull'));
         //            }
     } catch (Exception $e) {
         \Yii::$app->session->setFlash('error', $e->getMessage());
     }
     return $this->redirect(['index']);
 }
Beispiel #3
0
/* @var $model app\modules\post\models\PostSearch */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="search-form">

    <?php 
$form = ActiveForm::begin(['action' => ['index'], 'method' => 'post', 'options' => ['class' => 'form-inline']]);
?>
    
    <?php 
echo $form->field($model, 'title', ['template' => '{input}', 'inputOptions' => ['placeholder' => $model->getAttributeLabel('title')]])->label(false);
?>
    
    <?php 
echo $form->field($model, 'category_id', ['template' => '{input}'])->dropDownList(ArrayHelper::map(Category::find()->orderBy('left')->all(), 'id', 'fulltitle'), ['prompt' => 'Tất cả danh mục'])->label(false);
?>
    
    <?php 
echo $form->field($model, 'active', ['template' => '{input}'])->dropDownList([0 => 'Ngừng hoạt động', 1 => 'Hoạt động'], ['prompt' => 'Tất cả trạng thái'])->label(false);
?>

    <?php 
// echo $form->field($model, 'meta_title')
?>

    <?php 
// echo $form->field($model, 'meta_desciption')
?>

    <?php