/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['HeadCategories'])) { $model = new HeadCategories(); $model->attributes = $_POST['HeadCategories']; $model->id_name = "id-" . str_replace(" ", "-", $_POST['HeadCategories']['name']); $model->category = CategoriesMain::model()->findByPk($_POST['HeadCategories']['id_mc'])->name; if ($model->save()) { echo "sukses"; } else { print_r($model->getErrors()); } // $this->redirect(array('view','id'=>$model->id)); } // $this->render('create',array( // 'model'=>$model, // )); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = CategoriesMain::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
</form> </div> <div id="form-add-topic"> <H3>ADD TOPIC</H3> <img class="close-form-add-category" style="width:20px;position:absolute;top:45px;right:25px;" src="<?php echo Yii::app()->request->baseurl; ?> /img/delete.ico"> <form id="add-category-form"> <table cellpadding="10"> <tr><td>category</td><td> <select name="CategoriesMain[name]" required > <option value="">choose</option> <?php foreach (CategoriesMain::model()->findAll() as $c) { ?> <option value="<?php echo $c->id; ?> "><?php echo $c->name; ?> </option> <?php } ?> </select> </td> </tr> <tr><td>color</td><td><input name="CategoriesMain[color]" type="text" required maxlength="6" size="6" id="colorpickerField2" value="ff0000"></td></tr>