/** * Creates a new Commodity model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Commodity(); $model->beforeSave(true); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new Commodity(); if ($model->load(Yii::$app->request->post())) { $model->scenario = 'create'; // 获取用户输入的数据,验证并保存 $model->create_time = date('Y-m-d H:i:s'); //var_dump($model); $model->img = UploadedFile::getInstance($model, 'img'); $name = time() . '.' . $model->img->extension; $model->img->saveAs('uploads/images/' . $name); $model->img = '/uploads/images/' . $name; $model->uid = $this->user->id; $model->statu = Commodity::$_AUDIT_PEND; $platform = Platform::findOne($model->platform_id); $model->platform = $platform->name; $shop = Shop::findOne($model->shop_id); if (!empty($shop)) { $model->shop = $shop->shop_name; } 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(); //$shops = Shop::findAll('uid = :uid',[':uid'=>'']); return $this->render('create', array('model' => $model, 'shops' => $shops, 'platforms' => $platforms)); }