public function action_create() { $this->template->title = __('Thêm mới cung'); $this->template->section_title = __('Thêm mới cung'); $data = array(); if (Request::$method == 'POST') { $_cung = new Model_Horoscope_Cung(); #Load the validation rules, filters and callbacks $post = $_cung->validate_create($_POST); #Check that all fields are valid. if ($post->check()) { //validate file upload $validate = Validate::factory($_FILES); $validate->rules('hinh_anh', array('Upload::valid' => array(), 'Upload::not_empty' => array(), 'Upload::type' => array('Upload::type' => array('jpg', 'png', 'gif')), 'Upload::size' => array('1M'))); if ($validate->check()) { //begin save $post_values = $post->as_array(); //unset($post); //die(var_dump($post_values)); $_cung->alias = $post_values['alias']; //die(print_r($_FILES)); //save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644) $path = Upload::save($_FILES['hinh_anh'], $_cung->alias . '.jpg', 'assets/horoscope/cung/', 0777); //die(print_r($path)); $_cung->ten_cung = $post_values['ten_cung']; $_cung->hinh_anh = $path; $_cung->mieu_ta = $post_values['mieu_ta']; $_cung->nhan_dang_chung = $post_values['nhan_dang_chung']; $_cung->nhan_dang_nam = $post_values['nhan_dang_nam']; $_cung->nhan_dang_nu = $post_values['nhan_dang_nu']; $_cung->vi_tri = $post_values['vi_tri']; //post date format : dd-mm-yyyy (need to convert -> sql style: yyyy-mm-dd) list($d1, $m1, $y1) = explode('-', $post_values['tu_ngay']); $_cung->tu_ngay = '1970' . '-' . $m1 . '-' . $d1; list($d2, $m2, $y2) = explode('-', $post_values['den_ngay']); $_cung->den_ngay = '1970' . '-' . $m2 . '-' . $d2; $_cung->save(); Request::instance()->redirect('admin/horoscope_cung/index'); } else { #Repopulate $_POST data $_POST = $post->as_array(); //error $data['errors'] = $validate->errors(); } } else { //die("check done"); #Repopulate $_POST data //$_POST = array_intersect_key($post->as_array(), $_POST); $_POST = $post->as_array(); #Affects errors for further display $data['errors'] = $post->errors(); } } $added_cungs = Model_Horoscope_CungBLL::GetAllAddedCung(); $data['added'] = $added_cungs; $this->template->content = View::factory('horoscope/admin/cung/create', $data); }