/** * Creates a new product in the database * * If no data has been posted, a form with the needed fields will be rendered. If the data has * been posted, an attempt will be made to save. If successful, the user will be redirected to the * 'view' page for the new record, otherwise they will be notified of the failure. */ public function actionCreate() { if (isset($_POST['model'])) { //check if data has been posted $model = new items($_POST['model']); if ($model->save()) { //redirect to product view if successful testProject::setAlert('The item ' . $model->name . ' was successfully created.', 'success'); $this->redirect("items/view/{$model->id}"); } else { //create the alert message to notify of failure testProject::setAlert('We\'re sorry, but your changes could not be saved. Please try again.', 'danger'); } } //show the form $statuses = statuses::model()->getAll(); $vendors = vendors::model()->getAll(); $tags = tags::model()->getAll(); $this->render('create', array('statuses' => $statuses, 'vendors' => $vendors, 'tags' => $tags)); }