/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Teachers(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Teachers'])) { $model->attributes = $_POST['Teachers']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Teachers('insert'); $users_list = CHtml::listData(Users::model()->findAll(), 'id', 'username'); if (Yii::app()->request->isPostRequest) { $classroom = Yii::app()->request->getParam('Teachers'); $model->setAttributes($classroom); if (!Yii::app()->user->checkAccess('admin')) { $model->setAttribute('owner_id', Yii::app()->user->id); } if ($model->save()) { Yii::app()->user->setFlash('success', 'Преподаватель успешно создан'); $this->redirect(['index']); } } $this->render('form', ['model' => $model, 'users_list' => $users_list]); }
public function postCreate() { $image = Input::file('url'); $validator = Validator::make(array('image' => $image), array('image' => 'required|mimes:png,jpeg,gif'), array('mimes' => 'Tipo de imagen inválido, solo se admite los formatos PNG, JPEG, y GIF')); if ($validator->fails()) { return Redirect::to($this->route . '/create')->with('msg_succes', Lang::get('messages.teachers_create_img_err')); } else { $filename = $this->uploadImage($image); $teacher = new Teachers(); $teacher->content = Input::get('content'); $teacher->firstName = Input::get('firstName'); $teacher->lastName = Input::get('lastName'); $teacher->contact = Input::get('contact'); $teacher->status = 'draft'; $teacher->url = $filename; if ($teacher->save()) { return Redirect::to($this->route)->with('msg_success', Lang::get('messages.teachers_create', array('firstName' => $teacher->firstName, 'lastName' => $teacher->lastName))); } else { return Redirect::to($this->route)->with('msg_error', Lang::get('messages.teachers_create_err', array('firstName' => $teacher->firstName, 'lastName' => $teacher->lastName))); } } }