/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Tintuc(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Tintuc'])) { $model->attributes = $_POST['Tintuc']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->ma_tin)); } } $this->render('create', array('model' => $model)); }
public function post_add_tintuc() { $data = Input::all(); $valid = Validator::make($data, Tintuc::$add_tintuc_rules, Tintuc::$add_tintuc_language); if ($valid->passes()) { $img = $data['img']->move('public/img/news', $data['img']->getClientOriginalName()); if ($img) { $tintuc = new Tintuc(); $tintuc->img = 'public/img/news/' . $data['img']->getClientOriginalName(); $tintuc->title = Input::get('title'); $tintuc->mota = Input::get('mota'); $tintuc->noidung = Input::get('noidung'); $tintuc->user = Auth::user()->username; $tintuc->thoigian = date('d-m-Y'); $tintuc->save(); return Redirect::to(Input::get('url'))->with('tintuc_success', 'Đăng tin thành công'); } else { return Redirect::to(Input::get('url'))->with('tintuc_success', 'Đăng tin thành công'); } } else { return Redirect::to(Input::get('url'))->withInput()->with('tintuc_error', $valid->errors()->first()); } }