public static function edit($id, MenuForm $form) { $menu = Menu::findOne($id); if (!$menu) { return false; } $menu->cid = $form->cid; $menu->aid = $form->aid; $menu->title = $form->title; $menu->price = $form->price; $menu->favorable_price = $form->favorable_price; $menu->new = $form->new; $menu->provide_time = $form->provide_time; $menu->peppery = $form->peppery; $menu->status = $form->status; return $menu->save(); }
/** * 菜单图片管理 */ public function actionImg($id) { $info = Menu::findOne($id); !$info and $this->error('参数错误'); return $this->render('img', ['info' => $info]); }
<h5 class="heading">添加新菜单</h5> <hr/> <?php use app\models\sysadm\Menu; 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, 'title'); echo $form->field($model, 'cid')->dropDownList(Menu::categories()); echo $form->field($model, 'aid')->dropDownList(Menu::activities()); echo $form->field($model, 'price'); echo $form->field($model, 'favorable_price'); echo $form->field($model, 'new', ['template' => '{label}<div class="col-lg-3 radio">{input}</div><div class="col-lg-2">{error}</div>'])->radioList(Menu::newOptions()); echo $form->field($model, 'provide_time', ['template' => '{label}<div class="col-lg-3 radio">{input}</div><div class="col-lg-2">{error}</div>'])->radioList(Menu::provideOptions()); echo $form->field($model, 'peppery', ['template' => '{label}<div class="col-lg-4 radio">{input}</div><div class="col-lg-2">{error}</div>'])->radioList(Menu::peppery()); echo $form->field($model, 'status', ['template' => '{label}<div class="col-lg-3 radio">{input}</div><div class="col-lg-2">{error}</div>'])->radioList(Menu::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();
public function edit($id) { if ($this->validate()) { return Menu::edit($id, $this); } }