/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Origin(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Origin'])) { $model->attributes = $_POST['Origin']; if ($model->save() && $model->validate()) { date_default_timezone_set("Asia/Manila"); $activity = new Activity(); $activity->act_desc = 'Added Another Origin'; $activity->act_datetime = date('Y-m-d G:i:s'); $activity->act_by = User::model()->findByPK(Yii::app()->user->name)->emp_id; $activity->save(); $this->redirect(array('view', 'id' => $model->orig_id)); } } $this->render('create', array('model' => $model)); }
/** * Add Role for super user * * Add user have id = 1 to role's id = 1 */ public function addRootOrigin() { $rootOrigin = array('aid' => 1, 'rid' => 1); $origin = Origin::model()->findByPk($rootOrigin); if (empty($origin)) { $add = new Origin(); $add->attributes = $rootOrigin; try { $add->save(); $this->redirect('/admin'); } catch (Exception $ex) { $data['errmsg'] = $ex->getMessage(); $this->render('origin', $data); } } else { $this->redirect('/admin'); } }