/** * 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 $id the ID of the model to be loaded * @return Tintuc the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Tintuc::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function view_tintuc($id, $title) { if (Cache::has('view_tintuc' . $id)) { $data['tintuc'] = Cache::get('view_tintuc' . $id); } else { $data['tintuc'] = Cache::remember('view_tintuc' . $id, 15, function () use($id) { return Tintuc::find($id); }); } $data['title'] = $title; return View::make('template.view_tintuc', $data); }
echo $form->labelEx($model, 'anh'); ?> <?php echo $form->fileField($model, 'anh', array('size' => 60, 'maxlength' => 255)); ?> <?php echo $form->error($model, 'anh'); ?> </div> <div class="col-md-2"></div> <div class="col-md-4"> <?php echo $form->labelEx($model, 'trang_thai'); ?> <?php echo $form->dropDownList($model, 'trang_thai', Tintuc::trangthai(), array('class' => ' form-control')); ?> <?php echo $form->error($model, 'trang_thai'); ?> </div> </div> <div class="row"> <div class="col-md-1"></div> <div class="col-md-10"> <?php echo $form->labelEx($model, 'noi_dung'); ?> <?php echo $form->textArea($model, 'noi_dung', array('rows' => 6, 'cols' => 50, 'id' => 'noi_dung', 'class' => ' form-control')); ?>
public function post_edit_tintuc() { $data = Input::all(); $valid = Validator::make($data, Tintuc::$edit_tintuc_rules, Tintuc::$add_tintuc_language); if ($valid->passes()) { $tintuc = Tintuc::find(Input::get('id')); $tintuc->title = Input::get('title'); $tintuc->mota = Input::get('mota'); $tintuc->noidung = Input::get('noidung'); $tintuc->save(); return Redirect::to(Input::get('url'))->with('tintuc_success', 'Sửa tin thành công'); } else { return Redirect::to(Input::get('url'))->with('tintuc_error', $valid->errors()->first()); } }