Esempio n. 1
0
 public static function edit($id, CategoryForm $form)
 {
     $category = Category::findOne($id);
     if (!$category) {
         return false;
     }
     $category->name = $form->name;
     $category->status = $form->status;
     return $category->save();
 }
Esempio n. 2
0
 public static function categories()
 {
     $categories = Category::find(['status' => Category::STATUS_NORMAL])->asArray()->select('cid,name')->all();
     $options = ['' => '请选择'];
     if (!$categories) {
         return $options;
     }
     foreach ($categories as $row) {
         $options[$row['cid']] = $row['name'];
     }
     return $options;
 }
Esempio n. 3
0
 public function actionEdit($id)
 {
     $model = new CategoryForm(['scenario' => 'add']);
     if ($model->load(\Yii::$app->request->post()) and $model->edit($id)) {
         $this->success();
         $this->redirect('/category/list');
     }
     $category = Category::findOne($id);
     !$category and $this->error('参数错误');
     $model->name = $category->name;
     $model->status = $category->status;
     return $this->render('add', ['model' => $model]);
 }
Esempio n. 4
0
<h5 class="heading">添加菜单分类</h5>
<hr/>
<?php 
use app\models\sysadm\Category;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
$form = ActiveForm::begin(['options' => ['class' => 'form-horizontal'], 'fieldConfig' => ['labelOptions' => ['class' => 'col-lg-2 control-label'], 'template' => '{label}<div class="col-lg-3">{input}</div><div class="col-lg-2">{error}</div>']]);
echo $form->field($model, 'name');
echo $form->field($model, 'status', ['template' => '{label}<div class="col-lg-3 radio">{input}</div><div class="col-lg-2">{error}</div>'])->radioList(Category::status());
?>
		<div class="form-group">
			<div class="col-lg-2"></div>
			<div class="col-lg-1">
<?php 
echo Html::submitButton('提交', ['class' => 'btn btn-primary btn-block', 'name' => 'login-button']);
?>
			</div>
		</div>
<?php 
ActiveForm::end();
Esempio n. 5
0
 public function edit($id)
 {
     if ($this->validate()) {
         return Category::edit($id, $this);
     }
 }