コード例 #1
0
ファイル: PolicyController.php プロジェクト: nattaphat/cuse2
 /**
  * [policySaveAction for save policy]
  * @return [none] [redirect to policy page]
  */
 public function policySaveAction()
 {
     Input::flash();
     $data = Input::all();
     if (!isset($data['policy-status'])) {
         $data['policy-status'] = 'off';
     }
     // var_dump($data);exit;
     $rules = array('policy-text' => array('min:30', 'required'), 'policy-author' => array('required'), 'policy-status' => array('required'));
     // Build the custom messages array.
     $messages = array('policy-text.min' => 'กรุณาระบุเนื้อหานโยบายอย่างน้อย :min ตัวอักษร.', 'policy-text.required' => 'กรุณาระบุเนื้อหานโยบายคลังฯ', 'policy-author.required' => 'กรุณาระบุชื่อผู้สร้างนโยบาย');
     $policy_text = trim($data['policy-text']);
     // Create a new validator instance.
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         // Normally we would do something with the data.
         $policy = new Policy();
         $chk_pol = $policy->ckeckPolicyDuplicate(mb_strlen($policy_text));
         $policy->setTable('policy');
         if ($chk_pol) {
             $policy->policy_content = $policy_text;
             $policy->author = $data['policy-author'];
             $policy->status = $data['policy-status'] == 'on' ? True : False;
             $policy->policy_duty = $data['policy_duty'];
             $policy->save();
             return Redirect::to('policy-add')->with('success', 'บันทึกนโยบายคลังฯ สำเร็จ');
         } else {
             return Redirect::to('policy-add')->withErrors(array('มีนโยบายคลังฯ นี้อยุ่ในระบบแล้ว'));
         }
         // if($chk_pol)
         // {
         // 	return Redirect::to('policy-content')->withErrors('message','Existing Policy.');
         // }else
         // {
         // 	$policy->policy_content = $policy_text;
         // 	$policy->author = $data['policy-author'] ;
         // 	$policy->status = (($data['policy-status'] == 1) ? True : False);
         // 	//$policy->save();
         // 	return Redirect::to('policy-content')->with('success','Policy Added.');
         // }
     } else {
         //$errors = $validator->messages();
         return Redirect::to('policy-add')->withErrors($validator);
     }
 }