我怎样才能使在订购货物时有新的数据项时可以直接到货物表中去


how can I make when there is new data items in ordering goods can go directly to the tables of goods?

大家下午好不好意思,我想问我正在制作一个应用程序清单项目我有一个数据项目表和货物接收表所有表格数据输入方式为excel导入文件我怎样才能使在订购货物时有新的数据项可以直接进入货物表?谢谢你

这是我的控制器

public function actionImport(){
      $modelImport =  new 'yii'base'DynamicModel([
        'fileImport'=>'File Import',
      ]);
      $modelImport->addRule(['fileImport'],'required');
      $modelImport->addRule(['fileImport'],'file',['extensions'=>'ods,xls,xlsx']);
      if(Yii::$app->request->post()){
        $modelImport->fileImport = 'yii'web'UploadedFile::getInstance($modelImport,'fileImport');
        if ($modelImport->fileImport && $modelImport->validate()){
          $inputFileType = 'PHPExcel_IOFactory::identify($modelImport->fileImport->tempName);
          $objReader = 'PHPExcel_IOFactory::createReader($inputFileType);
          $objPHPExcel = $objReader->load($modelImport->fileImport->tempName);
          $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
          $baseRow = 1;
          while(!empty($sheetData[$baseRow]['A'])){
            $model = new PersediaanBarang();
            $model->rm_code = (string) $sheetData[$baseRow]['A'];
            $model->quantity = (string) $sheetData[$baseRow]['B'];
            $model->save();
            $baseRow++;
          }
          Yii::$app->getSession()->setFlash('success','Success');
        }else{
          Yii::$app->getSession()->setFlash('error','Error');
        }
        //return $this->redirect(['barang/index']);
      }
      return $this->render('import',[
        'modelImport'=>$modelImport,
      ]);
    }

SOLVE!!!!

<?php
namespace backend'controllers;
use Yii;
use backend'models'Penerimaan;
use backend'models'PenerimaanSearch;
use yii'web'Controller;
use yii'web'NotFoundHttpException;
use yii'filters'VerbFilter;
use backend'models'Barang;
/**
 * PenerimaanController implements the CRUD actions for Penerimaan model.
 */
class PenerimaanController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }
    /**
     * Lists all Penerimaan models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new PenerimaanSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
    /**
     * Displays a single Penerimaan model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }
    public function actionLihat()
    {
      $connection=  'Yii::$app->db;
      $users = $connection->createCommand('SELECT avg(price) as a FROM penerimaan')->queryAll();
      var_dump($users);
    }
    /**
     * Creates a new Penerimaan model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new Penerimaan();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
    /**
     * Updates an existing Penerimaan model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }
    /**
     * Deletes an existing Penerimaan model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();
        return $this->redirect(['index']);
    }
    /**
     * Finds the Penerimaan model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Penerimaan the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Penerimaan::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
    public function actionImport(){
      $model=new Penerimaan();
      $modelImport =  new 'yii'base'DynamicModel([
        'fileImport'=>'File Import',
      ]);
      $modelImport->addRule(['fileImport'],'required');
      $modelImport->addRule(['fileImport'],'file',['extensions'=>'ods,xls,xlsx']);
      if(Yii::$app->request->post()){
        $modelImport->fileImport = 'yii'web'UploadedFile::getInstance($modelImport,'fileImport');
        if ($modelImport->fileImport && $modelImport->validate()){
          $inputFileType = 'PHPExcel_IOFactory::identify($modelImport->fileImport->tempName);
          $objReader = 'PHPExcel_IOFactory::createReader($inputFileType);
          $objPHPExcel = $objReader->load($modelImport->fileImport->tempName);
          $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
          $baseRow = 1;
          while(!empty($sheetData[$baseRow]['A'])){
            $x = Barang::find()->where(['rm_code'=>$sheetData[$baseRow]['A']])->count();
            if($x==0){
              $connection = 'Yii::$app->db;
              $connection->createCommand()->insert('barang',['rm_code'=>$sheetData[$baseRow]['A']])->execute();
}
            $model = new Penerimaan();
            $model->rm_code = (string) $sheetData[$baseRow]['A'];
            $model->quantity = (string) $sheetData[$baseRow]['B'];
            $bulan = $_POST['Penerimaan']['bulan'];
            $model->bulan= $bulan;
            $model->save();
            $baseRow++;
          }
          Yii::$app->getSession()->setFlash('success','Success');
        }else{
          Yii::$app->getSession()->setFlash('error','Error');
        }
        return $this->redirect(['penerimaan/index']);
      }
      return $this->render('import',[
        'modelImport'=>$modelImport,
        'model'=>$model,
      ]);
    }
    public function actionBarang()
    {
        $searchModel = new PenerimaanSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        return $this->render('barang', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
}