backend/controllers/RestaurantController.php
/**
     * Creates a new Restaurant model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Restaurant model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Restaurant model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Restaurant();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $id = $model->restaurantId;
            $image = UploadedFile::getInstance($model, 'image');
            var_dump($image->getExtension());
            $imgName = "restaurant_$id".".".$image->getExtension();
            $image->saveAs(Yii::getAlias('@restaurantLocalPath').'/'.$imgName);
            $model->image = $imgName;
            $model->save();
            return $this->redirect(['view', 'id' => $model->restaurantId]);
        }
        return $this->render('create', [
            'model' => $model,
        ]);
    }
public function actionCreate ( ) { $ model = new Restaurant ( ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { $ id = $ model -> restaurantId ; $ image = UploadedFile :: getInstance ( $ model , 'image' ) ; var_dump ( $ image -> getExtension ( ) ) ; $ imgName = " restaurant_ $ id " . " . " . $ image -> getExtension ( ) ; $ image -> saveAs ( Yii :: getAlias ( '@restaurantLocalPath' ) . '/' . $ imgName ) ; $ model -> image = $ imgName ; $ model -> save ( ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> restaurantId ] ) ; } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new Restaurant model.
Creates a new Restaurant model .