/** * Creates a new Customers model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Customers(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->composer_id]); } else { return $this->render('create', ['model' => $model]); } }
public function readfile() { $filename = 'CustomersFile/Customers.txt'; $readfile = fopen($filename, 'r'); while ($str = fgets($readfile, 1024)) { $items = explode(';', $str); //print_r($items); $usr = User::findByFullname(iconv('CP1251', 'UTF-8', $items[1])); //print_r($usr); if (!isset($usr)) { continue; } echo '-->' . $usr->id . '<br>'; //echo $usr->username . '<br>'; echo trim($items[1]) . '<br>'; echo $items[0] . '<br>'; echo $items[2] . '<br>'; echo $items[3] . '<br>'; $tp = Typeprice::findOne(['type_price_name' => iconv('CP1251', 'UTF-8', $items[3])]); if (isset($tp)) { //print_r($tp); echo $tp->type_price_id; } else { echo '???'; $tp = new Typeprice(); $tp->type_price_name = iconv('CP1251', 'UTF-8', $items[3]); $tp->save(); } $customer = Customers::findOne(['customer_1c_id' => $items[0]]); if (isset($customer)) { echo $customer->customer_id; } else { echo '???'; $customer = new Customers(); $customer->customer_1c_id = $items[0]; $customer->user_id = $usr->id; $customer->customer_name = iconv('CP1251', 'UTF-8', $items[2]); $customer->typeprices_id = $tp->type_price_id; $customer->save(); } unset($customer); unset($tp); } fclose($readfile); }