Exemple #1
0
 /**
  * Index action (default)
  */
 public function action_index()
 {
     $this->template->title = __('Quản lý 12 cung');
     $this->template->section_title = __('Quản lý 12 cung');
     $data = array();
     $data['cungs'] = Model_Horoscope_CungBLL::GetAllCungForListing();
     $this->template->content = View::factory('horoscope/admin/cung/index', $data);
 }
Exemple #2
0
 /**
  * create actions
  */
 public function action_create()
 {
     $this->template->title = __('Thêm mới bài viết: xung - hợp cung');
     $this->template->section_title = __('Thêm mới bài viết: xung - hợp cung');
     $data = array();
     if (Request::$method == 'POST') {
         //print_r($_POST);
         $_story = new Model_Horoscope_XungHop();
         #Load the validation rules, filters and callbacks
         $post = $_story->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));
                 $_story->alias = $post_values['alias'];
                 $_story->cung_1 = $post_values['cung_1'];
                 $_story->cung_2 = $post_values['cung_2'];
                 //die(print_r($_FILES));
                 //save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644)
                 $save_dir = 'assets/horoscope/xung-hop/';
                 if (!file_exists($save_dir)) {
                     @mkdir($save_dir, $mode = 0777, $recursive = true);
                 }
                 $file_name = $_story->alias . '.jpg';
                 $path = Upload::save($_FILES['hinh_anh'], $_story->alias . '.jpg', $save_dir, 0777);
                 //die(print_r($path));
                 $_story->hinh_anh = "/" . $save_dir . $file_name;
                 $_story->tom_tat = trim($post_values['tom_tat']);
                 $_story->noi_dung = trim($post_values['noi_dung']);
                 $_story->url_nguon = trim($post_values['url_nguon']);
                 $_story->ngay_tao = date("Y-m-d");
                 $_story->kiem_tra = 'yes';
                 $_story->auto_get = false;
                 $_story->source_date = $_story->ngay_tao;
                 //post date format : dd-mm-yyyy (need to convert -> sql style: yyyy-mm-dd)
                 //die(print_r($_story->alias));
                 $_story->save();
                 Request::instance()->redirect('admin/horoscope_xunghop/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();
         }
     }
     $data['stories'] = Model_Horoscope_CungBLL::GetAllCungForListing();
     $this->template->content = View::factory('horoscope/admin/xung-hop/create', $data);
 }