Ejemplo n.º 1
0
 /**
  * Updates an existing Product 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);
     $model->updated = Yii::$app->formatter->format($model->updated, 'date');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->fileAttach($model);
         $model->updated = Yii::$app->formatter->format($model->updated, 'date');
         return $this->render('update', ['model' => $model, 'listCategory' => Category::getListCategory()]);
     } else {
         return $this->render('update', ['model' => $model, 'listCategory' => Category::getListCategory()]);
     }
 }
Ejemplo n.º 2
0
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Создать категорию', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'id', 'headerOptions' => ['class' => 'col-sm-1']], ['attribute' => 'name', 'format' => 'raw', 'value' => function ($category) {
    return Html::tag('a', $category->name, ['href' => Url::to(['update', 'id' => $category->id])]);
}], ['attribute' => 'parent_category_id', 'format' => 'raw', 'value' => function ($data) {
    if ($data->parent) {
        return Html::a($data->parent->name, Url::to(['admin/category/update', 'id' => $data->id]));
    }
}, 'filter' => Html::activeDropDownList($searchModel, 'parent_category_id', \yii\helpers\ArrayHelper::map(\app\modules\admin\models\Category::getListCategory(), 'id', 'name'), ['prompt' => 'Не выбрано'])], ['attribute' => 'active', 'format' => 'raw', 'value' => function ($category) {
    if ($category->active) {
        $mes = 'Да';
        $class = 'success';
    } else {
        $mes = 'Нет';
        $class = 'warning';
    }
    return Html::tag('span', $mes, ['class' => 'label label-' . $class]);
}, 'filter' => Html::activeDropDownList($searchModel, 'active', \app\modules\admin\models\Category::getYesNo(), ['prompt' => 'Не выбрано']), 'headerOptions' => ['class' => 'col-sm-1']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'headerOptions' => ['class' => 'col-sm-1']]]]);
?>

</div>
Ejemplo n.º 3
0
    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
    <?php 
echo $form->field($model, 'alias')->textInput(['maxlength' => true]);
?>
    <?php 
echo $form->field($model, 'active')->checkbox(['id' => 'check']);
?>
    <?php 
echo $form->field($model, 'parent_category_id')->dropDownList(ArrayHelper::map(\app\modules\admin\models\Category::getListCategory($model->isNewRecord ? [] : 'id!=' . $model->id), 'id', 'name'), ['prompt' => 'Не выбрано']);
?>

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

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

    <?php 
echo $form->field($model, 'image')->fileInput();
?>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">