private function addNewReview($requests) { //Если прищли данные с формы if (isset($requests)) { if (!empty($requests['ReviewAuthor']['name']) && !empty($requests['ReviewAuthor']['email']) && !empty($requests['ReviewElements']['parent_id']) && !empty($requests['ReviewElements']['review'])) { preg_match('|([a-z0-9_\\.\\-]{1,20})@([a-z0-9\\.\\-]{1,20})\\.([a-z]{2,4})|is', $requests['ReviewAuthor']['email'], $match); if (!empty($match)) { $model = ReviewAuthor::model()->find('email LIKE "' . $requests['ReviewAuthor']['email'] . '"'); if (!$model) { $model = new ReviewAuthor(); } $model->name = $requests['ReviewAuthor']['name']; $model->email = $requests['ReviewAuthor']['email']; if ($model->save()) { $modelElement = new ReviewElements(); $modelElement->parent_id = (int) $requests['ReviewElements']['parent_id']; $modelElement->author_id = $model->id; $modelElement->review = '<p>' . $requests['ReviewElements']['review'] . '</p>'; $modelElement->status = 0; $modelElement->save(); } } } } return true; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'update' page. */ public function actionCreate() { $this->breadcrumbs = array('Отзывы' => array('/review/review'), 'Новая запись'); $model = new ReviewElements(); $modelAuthor = new ReviewAuthor(); $root = ReviewRubrics::getRoot(new ReviewRubrics()); $catalog = $root->descendants()->findAll($root->id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // set attributes from get if (isset($_GET['ReviewElements'])) { $model->attributes = $_GET['ReviewElements']; } if (isset($_POST['ReviewElements'])) { $model->attributes = $_POST['ReviewElements']; if (isset($_POST['ReviewAuthor'])) { $modelAuthor->attributes = $_POST['ReviewAuthor']; $modelAuthor->save(); $model->author_id = $modelAuthor->id; } if ($model->save()) { $url = isset($_POST['go_to_list']) ? $this->listUrl('index') : $this->itemUrl('update', $model->id); $this->redirect($url); } } $this->render('create', array('model' => $model, 'root' => $root, 'catalog' => $catalog, 'modelAuthor' => $modelAuthor)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'update' page. */ public function actionCreate() { $model = new ReviewAuthor(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // set attributes from get if (isset($_GET['ReviewAuthor'])) { $model->attributes = $_GET['ReviewAuthor']; } if (isset($_POST['ReviewAuthor'])) { $model->attributes = $_POST['ReviewAuthor']; if ($model->save()) { $url = isset($_POST['go_to_list']) ? $this->listUrl('index') : $this->itemUrl('update', $model->id); $this->redirect($url); } } $this->render('create', array('model' => $model)); }