public function actionDelete($id) { Platform::findOne($id)->delete(); $this->redirect('/platform/index'); }
public function actionUpdate($id) { $model = Commodity::findOne($id); if (empty($model)) { throw new HttpException(404, '操作失败,商品不存在!'); } if ($this->user->rid != 1 && $model->uid != $this->user->id) { throw new HttpException(404, 'error'); } $oimg = $model->img; if ($model->load(Yii::$app->request->post())) { $img = UploadedFile::getInstance($model, 'img'); if (!is_null($img)) { $model->img = $img; $name = time() . '.' . $model->img->extension; $model->img->saveAs('uploads/images/' . $name); $model->img = '/uploads/images/' . $name; } else { $model->img = $oimg; } $platform = Platform::findOne($model->platform_id); $model->platform = $platform->name; $shop = Shop::findOne($model->shop_id); if (!empty($shop)) { $model->shop = $shop->shop_name; } $model->statu = Commodity::$_AUDIT_PEND; if ($model->save()) { $this->redirect('/commodity/index'); } else { var_dump($model->errors); } } $shops = array(); if ($this->user->rid == 3) { $shops = Shop::find()->where('uid = :uid', [':uid' => $this->user->id])->all(); } else { $shops = Shop::find()->all(); } $platforms = Platform::find()->all(); return $this->render('update', array('model' => $model, 'shops' => $shops, 'platforms' => $platforms)); }