/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Phones(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Phones'])) { $model->attributes = $_POST['Phones']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function addAction() { $phones = new Phones(); $producer = PhonesProducers::findFirst("name = '" . $this->request->getPost('producer') . "'"); $producerId = $producer->id; $phones->producer_id = $producerId; $OS = OperatingSystems::findFirst("name = '" . $this->request->getPost('OS') . "'"); $OSId = $OS->id; $phones->operating_system_id = $OSId; $phones->model = $this->request->getPost('model'); $phones->save(); $this->flash->success("Phone was successfully added."); $this->dispatcher->forward(['action' => 'index']); }
public function actionParse($from = null, $to = null, $id = null, $nocache = null) { if ($id) { $from = $id; $to = $id + 1; } if (!$from) { $this->stop("(("); } $flag_working = true; $ank_id = intval($from); $tries = 0; while ($flag_working) { if ($ank_id == $to) { $this->stop("All done"); } //sleep(2); $this->writeln("Parsing {$ank_id}"); $html = $this->getHtml($ank_id, $nocache == 1 ? false : true); if (preg_match('/' . $this->stopWord . '/uism', $html)) { $tries++; $ank_id++; $this->writeln($this->stopWord); if ($tries == 5) { return $this->stop("I'm stopping"); } continue; } else { $tries = 0; } // parse preg_match('/Жизненное\\s+кредо<\\/td>(.+?)<\\/td>/xuism', $html, $matches); $ro = preg_replace('/\\s\\s+/', ' ', $matches[0]); //var_dump($matches); $phone = $this->capturePhone($matches[0]); if (!$phone) { preg_match('/(Дополнительная\\s+информация\\s+\\(несколько\\s+слов\\s+о\\s+себе\\s+и\\s+своих\\s+увлечениях\\)<\\/td>(.+?)<\\/td>)/xuism', $html, $matches); if (isset($matches[0])) { $ro = preg_replace('/\\s\\s+/', ' ', $matches[0]); $phone = $this->capturePhone($matches[0]); } if (!$phone) { $this->no_phone[] = $this->anketUrl . $ank_id; $this->writeln("no phone"); $ank_id++; continue; } } $this->writeln($phone); // save $phone_model = Phones::model()->findByAttributes(array('phone' => $phone)); if (!$phone_model) { $phone_model = new Phones(); $phone_model->phone = $phone; if (!$phone_model->save()) { $this->stop('failed to save $phone_model'); } } $anket_model = Ankets::model()->findByAttributes(array('id' => $ank_id)); if (!$anket_model) { $anket_model = new Ankets(); $anket_model->id = $ank_id; $anket_model->phone_id = $phone_model->id; if (!$anket_model->save()) { $this->stop('failed to save $anket_model'); } } $ank_id++; } }