?> <h2>It should create a valid Review object when all input is provided</h2> <?php $validTest = array("firstName" => "Kay", "lastName" => "Robbins", "submissionID" => "R3023", "score" => "5", "review" => "This was a great presentation"); $s1 = new Review($validTest); echo "The object is: {$s1}<br>"; $test1 = is_object($s1) ? '' : 'Failed:It should create a valid object when valid input is provided<br>'; echo $test1; $test2 = empty($s1->getErrors()) ? '' : 'Failed:It not have errors when valid input is provided<br>'; echo $test2; ?> <h2>It should extract the parameters that went in</h2> <?php $props = $s1->getParameters(); print_r($props); ?> <h2>It should have an error when the first name contains invalid characters</h2> <?php $invalidTest = array("firstName" => "krobbins\$"); $s1 = new Review($invalidTest); $test2 = empty($s1->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test2; echo "The error for firstName is: " . $s1->getError('firstName') . "<br>"; echo "The object is: {$s1}<br>"; ?> </body> </html>
public function actionCreate() { $model = new Review(); if (isset($_POST['rating1'], $_POST['product_id'])) { $rId = $this->addRate($_POST['rating1'], $_POST['product_id']); } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['review_title'])) { $model->review_title = $_POST['review_title']; $model->review_content = $_POST['review_content']; $model->product_id = $_POST['product_id']; //echo $id; die(); // $ratingIdfromSaveRating=new CHttpSession; // $ratingIdfromSaveRating->open(); if ($rId) { $model->rating_id = $rId; // strip_tags($ratingIdfromSaveRating['rating_id']); $model->user_id = Yii::app()->user->user_id; //$model->attributes=$_POST['Review']; if ($model->save()) { // echo var_dump($model); die(); } else { die(var_dump($model->getErrors())); } //echo 'not in'; die(); // $this->redirect(array('view','id'=>$model->review_id)); } } $this->render('create', array('model' => $model, 'productId' => $model->product_id)); }