Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FuelPHP 実践 Validation

2no
July 08, 2012
12k

FuelPHP 実践 Validation

初発表資料

2no

July 08, 2012
Tweet

Transcript

  1. ΞδΣϯμ 1. جຊతͳ࢖͍ํ 2. Τϥʔϝοηʔδ 3. ϧʔϧʹ͍ͭͯ 1. ಠࣗόϦσʔγϣϯ 2.

    ಠࣗϑΟϧλ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  2. 1. جຊతͳ࢖͍ํ 24 $val = \Validation::forge(); 25 26 $val->add('name', '໊લ')

    27 ->add_rule('trim') 28 ->add_rule('required') 29 ->add_rule('max_length', 20); 30 31 $val->add_field('email', 'ϝʔϧΞυϨε', 32 'trim|required|valid_email'); 33 34 if ($val->run()) 35 { 36 // ੒ޭ࣌ͷॲཧ 37 } 38 else 39 { 40 // ࣦഊ࣌ͷॲཧ 41 } 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  3. 1. جຊతͳ࢖͍ํ 24 $val = \Validation::forge(); → Validation ΦϒδΣΫτͷੜ੒ →

    add ϝιουͰϑΟʔϧυ໊ͱϥϕϧͷ௥Ճ ɹ ଓ͍ͯɺ add_ruleϝιουͰϧʔϧ ʢݕূɾ੔ܗʣ Λ௥Ճ 26 $val->add('name', '໊લ') 27 ->add_rule('trim') 28 ->add_rule('required') 29 ->add_rule('max_length', 20); 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  4. 1. جຊతͳ࢖͍ํ → add_field ϝιου͸ɺ ɹ ϑΟʔϧυ໊ɺ ϥϕϧɺ ϧʔϧ ʢݕূɾ੔ܗʣ

    ΛҰׅࢦఆ → run ϝιουͰόϦσʔγϣϯ࣮ߦɻ ɹ ໰୊͕ແ͚Ε͹ TRUE Λฦ͢ɻ 31 $val->add_field('email', 'ϝʔϧΞυϨε', 32 'trim|required|valid_email'); 34 if ($val->run()) 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  5. 34 $errors = !$val->run() ? $val->error() : array(); 35 $values

    = $val->validated(); 36 37 foreach ($errors as $key => $error) 38 { 39 $values[$key] = $error->value; 40 } ࣗ෼ͷ৔߹ɺΤϥʔ͕ൃੜͯ͠΋੔ܗ్தͷ஋͸ཉ͍͠ͷ ͰɺԼهͷ༷ʹ͍ͯ͠·͢ɻ 1. جຊతͳ࢖͍ํ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  6. 34 $errors = !$val->run() ? $val->error() : array(); 35 $values

    = $val->validated(); 36 37 foreach ($errors as $key => $error) 38 { 39 $values[$key] = $error->value; 40 } ࣗ෼ͷ৔߹ɺΤϥʔ͕ൃੜͯ͠΋੔ܗ్தͷ஋͸ཉ͍͠ͷ ͰɺԼهͷ༷ʹ͍ͯ͠·͢ɻ 1. جຊతͳ࢖͍ํ 1.2.1 @wakuworks גࣜձࣾ Τϥʔൃੜ࣌ͷ஋ 12೥7݄8೔೔༵೔
  7. 76 'language' => 'ja', 77 'language_fallback' => 'en', 78 'locale'

    => 'ja_JP', 1.2.1 @wakuworks גࣜձࣾ 2. Τϥʔϝοηʔδ APPPATH/config/config.php ΤϥʔϝοηʔδΛઃఆ͢ΔલʹɺݴޠΛ೔ຊޠʹมߋ 12೥7݄8೔೔༵೔
  8. 76 'language' => 'ja', 77 'language_fallback' => 'en', 78 'locale'

    => 'ja_JP', 1.2.1 @wakuworks גࣜձࣾ 2. Τϥʔϝοηʔδ APPPATH/config/config.php ΤϥʔϝοηʔδΛઃఆ͢ΔલʹɺݴޠΛ೔ຊޠʹมߋ ͜ΕͰ APPPATH/lang/ja Λݟʹߦ͘Α͏ʹͳΔɻ ݴޠϑΝΠϧ͕ແ͚Ε͹ɺࣗಈతʹ language_fallback Ͱઃ ఆ͍ͯ͠Δ en Λݟʹߦ͘ͷͰ҆৺ 12೥7݄8೔೔༵೔
  9. 2. Τϥʔϝοηʔδ 1 <?php 2 return array( 3 'required' =>

    ':label ͸ඞਢ߲໨Ͱ͢ɻ', 4 'min_length' => ':label ͕ :param:1 จࣈະຬͰ͢ɻ', 5 'max_length' => ':label ͕ :param:1 จࣈΛ௒͍͑ͯ·͢ɻ', 6 'exact_length' => ':label ͕ :param:1 จࣈͰ͸͋Γ·ͤΜɻ', 7 'match_value' => ':label ͸ :param:1 ͱҰக͠·ͤΜɻ', 8 'match_pattern' => ':label ͸ :param:1 ͱҰக͢ΔύλʔϯͰ͸͋Γ·ͤΜɻ', 9 'match_field' => ':label ͸ :param:1 ͱҟͳΓ·͢ɻ', 10 'valid_email' => ':label ͸༗ޮͳϝʔϧΞυϨεͰ͸͋Γ·ͤΜɻ', 11 'valid_emails' => ':label ʹ༗ޮͰͳ͍ϝʔϧΞυϨεؚ͕·Ε͍ͯ·͢ɻ', 12 'valid_url' => ':label ͸༗ޮͳURLͰ͸͋Γ·ͤΜɻ', 13 'valid_ip' => ':label ͸༗ޮͳIPΞυϨεͰ͸͋Γ·ͤΜɻ', 14 'numeric_min' => ':label ͷ஋͕ :param:1 ະຬͰ͢ɻ', 15 'numeric_max' => ':label ͷ஋͕ :param:1 Λ௒͍͑ͯ·͢ɻ', 16 'valid_string' => ':label ʹෆਖ਼ͳจࣈؚ͕·Ε͍ͯ·͢ɻ', 17 ); APPPATH/lang/ja/validation.php 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  10. APPPATH/modules/hoge/lang/ja/validation.php 1 <?php 2 return array( 3 'required' => 'hogeϞδϡʔϧ༻ͷΤϥʔϝοηʔδ',

    4 ); ͜ͷ৔߹ɺrequired Ҏ֎ͷΤϥʔϝοηʔδ͸ σϑΥϧτ͕࢖ΘΕΔɻ 2. Τϥʔϝοηʔδ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  11. 26 $val->add('name', '໊લ') 27 ->add_rule('trim') 28 ->add_rule('required') 29 ->add_rule('max_length', 20);

    31 $val->add_field('email', 'ϝʔϧΞυϨε', 32 'trim|required|valid_email'); 3. ϧʔϧʹ͍ͭͯ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  12. 26 $val->add('name', '໊લ') 27 ->add_rule('trim') 28 ->add_rule('required') 29 ->add_rule('max_length', 20);

    31 $val->add_field('email', 'ϝʔϧΞυϨε', 32 'trim|required|valid_email'); ϧʔϧ 3. ϧʔϧʹ͍ͭͯ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  13. 26 $val->add('name', '໊લ') 27 ->add_rule('trim') 28 ->add_rule('required') 29 ->add_rule('max_length', 20);

    31 $val->add_field('email', 'ϝʔϧΞυϨε', 32 'trim|required|valid_email'); ϧʔϧ ύΠϓͭͳ͗ͷϧʔϧ 3. ϧʔϧʹ͍ͭͯ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  14. 3. ϧʔϧʹ͍ͭͯ ೋ௨Γͷϧʔϧ • ݕূʢόϦσʔτʣ ໭Γ஋͕ BOOL Ͱ͋Δ৔߹ 1.2.1 @wakuworks

    גࣜձࣾ $val->add('id', 'Ϣʔβʔ ID') ->add_rule(function($val) { return !!$val; }); 12೥7݄8೔೔༵೔
  15. 3. ϧʔϧʹ͍ͭͯ ೋ௨Γͷϧʔϧ • ݕূʢόϦσʔτʣ ໭Γ஋͕ BOOL Ͱ͋Δ৔߹ 1.2.1 @wakuworks

    גࣜձࣾ $val->add('id', 'Ϣʔβʔ ID') ->add_rule(function($val) { return !!$val; }); TRUE or FALSE 12೥7݄8೔೔༵೔
  16. 3. ϧʔϧʹ͍ͭͯ ೋ௨Γͷϧʔϧ • ݕূʢόϦσʔτʣ ໭Γ஋͕ BOOL Ͱ͋Δ৔߹ • ੔ܗʢϑΟϧλʣ

    ໭Γ஋͕ BOOL Ͱ͸ͳ͍৔߹ 1.2.1 @wakuworks גࣜձࣾ $val->add('id', 'Ϣʔβʔ ID') ->add_rule(function($val) { return !!$val; }); $val->add('id', 'Ϣʔβʔ ID') ->add_rule(function($val) { return trim($val); }); TRUE or FALSE 12೥7݄8೔೔༵೔
  17. add_rule Ͱࢦఆग़དྷΔϧʔϧ • FuelPHP ଆͰ༻ҙ͍ͯ͠Δϧʔϧ • add_callable, add_model Ͱొ࿥ͨ͠ϧʔϧ •

    ίʔϧόοΫ ϏϧτΠϯɺϢʔβఆٛؔ਺ɺ ΠϯελϯεϝιουɺΫϥεϝιουɺແ໊ؔ਺ 3. ϧʔϧʹ͍ͭͯ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  18. 3. ϧʔϧʹ͍ͭͯ add_field Ͱࢦఆग़དྷΔϧʔϧ • FuelPHP ଆͰ༻ҙ͍ͯ͠Δϧʔϧ • add_callable, add_model

    Ͱొ࿥ͨ͠ϧʔϧ • ίʔϧόοΫ ϏϧτΠϯɺϢʔβఆٛؔ਺ɺ ΠϯελϯεϝιουɺΫϥεϝιουɺແ໊ؔ਺ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  19. • required • min_length • max_length • exact_length • match_value

    • match_pattern • match_field 3. ϧʔϧʹ͍ͭͯ 1.2.1 @wakuworks גࣜձࣾ FuelPHP ଆ͕༻ҙ͍ͯ͠Δϧʔϧ • valid_email • valid_emails • valid_url • valid_ip • numeric_min • numeric_max • valid_string 12೥7݄8೔೔༵೔
  20. 1 <?php 2 class MyRules 3 { 4 public static

    function _validation_is_upper($val) 5 { 6 return $val === strtoupper($val); 7 } 8 } 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ APPPATH/classes/myrules.php 12೥7݄8೔೔༵೔
  21. 1 <?php 2 class MyRules 3 { 4 public static

    function _validation_is_upper($val) 5 { 6 return $val === strtoupper($val); 7 } 8 } 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ APPPATH/classes/myrules.php ઀಄ࣙʢඞਢʣ 12೥7݄8೔೔༵೔
  22. 24 $val = \Validation::forge(); 25 $val->add_callable('MyRules'); 26 27 $val->add('name', '໊લ')

    28 ->add_rule('is_upper'); 29 $val->add_field('email', 'ϝʔϧΞυϨε', 'is_upper'); 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ APPPATH/lang/ja/validation.php 1 <?php 2 return array( 3 'is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ', 4 ); 12೥7݄8೔೔༵೔
  23. 24 $val = \Validation::forge(); 25 $val->add_callable('MyRules'); 26 27 $val->add('name', '໊લ')

    28 ->add_rule('is_upper'); 29 $val->add_field('email', 'ϝʔϧΞυϨε', 'is_upper'); 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ Ϋϥε໊·ͨ͸ͦͷΠϯελϯεΛೖΕΔ APPPATH/lang/ja/validation.php 1 <?php 2 return array( 3 'is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ', 4 ); 12೥7݄8೔೔༵೔
  24. 24 $val = \Validation::forge(); 25 $val->add_callable('MyRules'); 26 27 $val->add('name', '໊લ')

    28 ->add_rule('is_upper'); 29 $val->add_field('email', 'ϝʔϧΞυϨε', 'is_upper'); 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ Ϋϥε໊·ͨ͸ͦͷΠϯελϯεΛೖΕΔ ௥Ճͨ͠ϧʔϧ APPPATH/lang/ja/validation.php 1 <?php 2 return array( 3 'is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ', 4 ); 12೥7݄8೔೔༵೔
  25. 1 <?php 2 class MyRules 3 { 4 public static

    function is_upper($val) 5 { 6 return $val === strtoupper($val); 7 } 8 } APPPATH/classes/myrules.php 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(array('MyRules', 'is_upper')) 33 ->add_rule(array(new MyRules(), 'is_upper')); 12೥7݄8೔೔༵೔
  26. APPPATH/lang/ja/validation.php 1 <?php 2 return array( 3 'MyRules:is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ',

    4 ); 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  27. 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(function($val) { 33 if ($val

    !== strtolower($val)) 34 { 35 \Validation::active()->set_message( 36 'closure', 37 ':label͸খจࣈͰೖྗ͍ͯͩ͘͠͞ɻ'); 38 return false; 39 } 40 return true; 41 }); 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  28. 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(function($val) { 33 if ($val

    !== strtolower($val)) 34 { 35 \Validation::active()->set_message( 36 'closure', 37 ':label͸খจࣈͰೖྗ͍ͯͩ͘͠͞ɻ'); 38 return false; 39 } 40 return true; 41 }); 3-1. ಠࣗόϦσʔγϣϯ 1.2.1 @wakuworks גࣜձࣾ ϧʔϧ໊͕ closure ʹͳΔ఺ʹ஫໨ 12೥7݄8೔೔༵೔
  29. 3-2. ಠࣗϑΟϧλ 1 <?php 2 class MyRules 3 { 4

    public static function to_upper($val) 5 { 6 return strtoupper($val); 7 } 8 } APPPATH/classes/myrules.php 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(array('MyRules', 'to_upper')) 33 ->add_rule(array(new MyRules(), 'to_lower')); 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  30. ແ໊ؔ਺Λ༻͍Δ৔߹ 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(function($val) { 33 return

    strtolower(trim($val)); 34 }); 3-2. ಠࣗϑΟϧλ 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  31. 3-2. ಠࣗϑΟϧλ 1.2.1 @wakuworks גࣜձࣾ 1 <?php 2 class Filter

    3 { 4 public static function settype($val, $type) 5 { 6 settype($val, $type); 7 return $val; 8 } 9 // ଞͷॲཧ͕ଓ͘ 10 } APPPATH/classes/filter.php ࣗ෼͸ Filter ΫϥεͳΔ΋ͷΛ࡞ͬͯɺ ͦ͜ʹॲཧΛ·ͱΊ͍ͯ·͢ɻ 12೥7݄8೔೔༵೔
  32. 3-2. ಠࣗϑΟϧλ 1.2.1 @wakuworks גࣜձࣾ 24 $val = \Validation::forge(); 25

    26 $val->add('age', '೥ྸ') 27 ->add_rule(array('Filter', 'settype'), 'integer'); 28 29 $errors = !$val->run() ? $val->error() : array(); 30 $values = $val->validated(); 31 32 foreach ($errors as $key => &$error) 33 { 34 $values[$key] = $error->value; 35 $error = ''.$error; 36 } ࢖ͬͯΈΔͱ͜Μͳײ͡ 12೥7݄8೔೔༵೔
  33. 3-2. ಠࣗϑΟϧλ 1.2.1 @wakuworks גࣜձࣾ 24 $val = \Validation::forge(); 25

    26 $val->add('age', '೥ྸ') 27 ->add_rule(array('Filter', 'settype'), 'integer'); 28 29 $errors = !$val->run() ? $val->error() : array(); 30 $values = $val->validated(); 31 32 foreach ($errors as $key => &$error) 33 { 34 $values[$key] = $error->value; 35 $error = ''.$error; 36 } ࢖ͬͯΈΔͱ͜Μͳײ͡ 12೥7݄8೔೔༵೔
  34. 1.2.1 @wakuworks גࣜձࣾ 7 $post = array( 8 'email1' =>

    ' [email protected] ', 9 'email2' => ' [email protected] ' 10 ); 11 12 $val = \Validation::forge(); 13 14 $val->add('email1', 'ϝʔϧΞυϨε') 15 ->add_rule('trim') 16 ->add_rule('required') 17 ->add_rule('valid_email'); 18 19 $val->add('email2', 'ϝʔϧΞυϨεʢ֬ೝʣ') 20 ->add_rule('trim') 21 ->add_rule('required') 22 ->add_rule('match_field', 'email1'); 23 24 $val->run($post); ΤϥʔͱͳΔྫɿ 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  35. 680 public function _validation_match_field($val, $field) 681 { 682 if ($this->input($field)

    !== $val) 683 { 684 $validating = $this->active_field(); 685 throw new \Validation_Error($validating, $val, array('match_field' => array($field)), array($this- >field($field)->label)); 686 } 687 688 return true; 689 } 1.2.1 @wakuworks גࣜձࣾ COREPATH/classes/validation.php 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  36. 680 public function _validation_match_field($val, $field) 681 { 682 if ($this->input($field)

    !== $val) 683 { 684 $validating = $this->active_field(); 685 throw new \Validation_Error($validating, $val, array('match_field' => array($field)), array($this- >field($field)->label)); 686 } 687 688 return true; 689 } 1.2.1 @wakuworks גࣜձࣾ COREPATH/classes/validation.php ϑΟϧλલͷ஋Ͱൺֱ͞ΕͯΔ… 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  37. 1 <?php 2 class MyRules 3 { 4 public static

    function _validation_match_validated_field( 5 $val, $field 6 ) { 7 $active = \Validation::active(); 8 $field_val = $active->validated($field); 9 if (!$field_val) 10 { 11 $error = $active->error($field); 12 $field_val = $error 13 ? $error->value 14 : $active->input($field); 15 } 16 return $field_val === $val; 17 } 18 } 1.2.1 @wakuworks גࣜձࣾ APPATH/classes/myrules.php 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  38. 39 $post = array( 40 'email1' => ' [email protected] ',

    41 'email2' => ' [email protected] ' 42 ); 43 44 $val = \Validation::forge(); 45 $val->add_callable('MyRules'); 46 47 $val->add('email1', 'ϝʔϧΞυϨε') 48 ->add_rule('trim') 49 ->add_rule('required') 50 ->add_rule('valid_email'); 51 52 $val->add('email2', 'ϝʔϧΞυϨεʢ֬ೝʣ') 53 ->add_rule('trim') 54 ->add_rule('required') 55 ->add_rule('match_validated_field', 'email1'); 56 57 $val->run($post); 1.2.1 @wakuworks גࣜձࣾ ৽͍͠ϧʔϧʹมߋޙɿ 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  39. 39 $post = array( 40 'email1' => ' [email protected] ',

    41 'email2' => ' [email protected] ' 42 ); 43 44 $val = \Validation::forge(); 45 $val->add_callable('MyRules'); 46 47 $val->add('email1', 'ϝʔϧΞυϨε') 48 ->add_rule('trim') 49 ->add_rule('required') 50 ->add_rule('valid_email'); 51 52 $val->add('email2', 'ϝʔϧΞυϨεʢ֬ೝʣ') 53 ->add_rule('trim') 54 ->add_rule('required') 55 ->add_rule('match_validated_field', 'email1'); 56 57 $val->run($post); 1.2.1 @wakuworks גࣜձࣾ ৽͍͠ϧʔϧʹมߋޙɿ ϧʔϧͷ௥Ճ 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  40. 39 $post = array( 40 'email1' => ' [email protected] ',

    41 'email2' => ' [email protected] ' 42 ); 43 44 $val = \Validation::forge(); 45 $val->add_callable('MyRules'); 46 47 $val->add('email1', 'ϝʔϧΞυϨε') 48 ->add_rule('trim') 49 ->add_rule('required') 50 ->add_rule('valid_email'); 51 52 $val->add('email2', 'ϝʔϧΞυϨεʢ֬ೝʣ') 53 ->add_rule('trim') 54 ->add_rule('required') 55 ->add_rule('match_validated_field', 'email1'); 56 57 $val->run($post); 1.2.1 @wakuworks גࣜձࣾ ৽͍͠ϧʔϧʹมߋޙɿ ϧʔϧͷ௥Ճ ϧʔϧΛࢦఆ 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  41. 1 <?php 2 return array( 3 'match_validated_field' => ':label ͸

    :param:1 ͱҰக͠·ͤΜɻ', 4 ); 1.2.1 @wakuworks גࣜձࣾ APPPATH/lang/ja/validation.php ৽͍͠ϧʔϧʹର͠ɺΤϥʔϝοηʔδΛઃఆ͓ͯ͘͠ɻ 4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ 12೥7݄8೔೔༵೔
  42. 1 <?php 2 return array( 3 'required' => ':labelΛೖྗ͍ͯͩ͘͠͞', 4

    ); APPPATH/lang/ja/validation.php 1 <?php 2 return array( 3 'gender' => array( 4 'required' => ':labelΛબ୒͍ͯͩ͘͠͞ɻ', 5 ), 6 ); APPPATH/lang/ja/error.php 1.2.1 @wakuworks גࣜձࣾ 4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ 12೥7݄8೔೔༵೔
  43. 1 <?php 2 return array( 3 'required' => ':labelΛೖྗ͍ͯͩ͘͠͞', 4

    ); APPPATH/lang/ja/validation.php 1 <?php 2 return array( 3 'gender' => array( 4 'required' => ':labelΛબ୒͍ͯͩ͘͠͞ɻ', 5 ), 6 ); APPPATH/lang/ja/error.php ϑΟʔϧυ໊ 1.2.1 @wakuworks גࣜձࣾ 4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ 12೥7݄8೔೔༵೔
  44. 1 <?php 2 return array( 3 'required' => ':labelΛೖྗ͍ͯͩ͘͠͞', 4

    ); APPPATH/lang/ja/validation.php 1 <?php 2 return array( 3 'gender' => array( 4 'required' => ':labelΛબ୒͍ͯͩ͘͠͞ɻ', 5 ), 6 ); APPPATH/lang/ja/error.php ϑΟʔϧυ໊ ϧʔϧ໊ 1.2.1 @wakuworks גࣜձࣾ 4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ 12೥7݄8೔೔༵೔
  45. 32 $errors = !$val->run($post) ? $val->error() : array(); 33 $values

    = $val->validated(); 34 35 $err = \Lang::load('error'); 36 foreach ($errors as $key => &$error) 37 { 38 $values[$key] = $error->value; 39 if (isset($err[$key][$error->rule])) 40 { 41 $error = $error->get_message( 42 $err[$key][$error->rule]); 43 } 44 else 45 { 46 $error = ''.$error; 47 } 48 } 1.2.1 @wakuworks גࣜձࣾ 4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ 12೥7݄8೔೔༵೔
  46. 32 $errors = !$val->run($post) ? $val->error() : array(); 33 $values

    = $val->validated(); 34 35 $err = \Lang::load('error'); 36 foreach ($errors as $key => &$error) 37 { 38 $values[$key] = $error->value; 39 if (isset($err[$key][$error->rule])) 40 { 41 $error = $error->get_message( 42 $err[$key][$error->rule]); 43 } 44 else 45 { 46 $error = ''.$error; 47 } 48 } ݴޠϑΝΠϧͷಡΈࠐΈ 1.2.1 @wakuworks גࣜձࣾ 4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ 12೥7݄8೔೔༵೔
  47. 32 $errors = !$val->run($post) ? $val->error() : array(); 33 $values

    = $val->validated(); 34 35 $err = \Lang::load('error'); 36 foreach ($errors as $key => &$error) 37 { 38 $values[$key] = $error->value; 39 if (isset($err[$key][$error->rule])) 40 { 41 $error = $error->get_message( 42 $err[$key][$error->rule]); 43 } 44 else 45 { 46 $error = ''.$error; 47 } 48 } ݴޠϑΝΠϧͷಡΈࠐΈ Τϥʔϝοηʔδͷऔಘ 1.2.1 @wakuworks גࣜձࣾ 4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ 12೥7݄8೔೔༵೔
  48. 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ 14 <form action="{ૹ৴ઌ}" method="post"> 15 <p><input type="text" name="hoge[0]"></p>

    16 <p><input type="text" name="hoge[1]"></p> 17 <p><input type="text" name="hoge[2]"></p> 18 <p><input type="submit" name="ૹ৴"></p> 19 </form> ୯७ʹ name ΛೖΕͯ 26 $val->add('hoge[0]'); 27 $val->add('hoge[1]'); 28 $val->add('hoge[2]'); 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  49. 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ 14 <form action="{ૹ৴ઌ}" method="post"> 15 <p><input type="text" name="hoge[0]"></p>

    16 <p><input type="text" name="hoge[1]"></p> 17 <p><input type="text" name="hoge[2]"></p> 18 <p><input type="submit" name="ૹ৴"></p> 19 </form> ୯७ʹ name ΛೖΕͯ RUN 26 $val->add('hoge[0]'); 27 $val->add('hoge[1]'); 28 $val->add('hoge[2]'); 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  50. 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ 14 <form action="{ૹ৴ઌ}" method="post"> 15 <p><input type="text" name="hoge[0]"></p>

    16 <p><input type="text" name="hoge[1]"></p> 17 <p><input type="text" name="hoge[2]"></p> 18 <p><input type="submit" name="ૹ৴"></p> 19 </form> ୯७ʹ name ΛೖΕͯ RUN ஋͕औΕͳ͍… 26 $val->add('hoge[0]'); 27 $val->add('hoge[1]'); 28 $val->add('hoge[2]'); 1.2.1 @wakuworks גࣜձࣾ 12೥7݄8೔೔༵೔
  51. ͜ͷࢦఆํ๏͸ Config Ͱ༻͍͍ͯΔ΋ͷͱಉ͡ɻ ͝ஸೡʹΩʔ΋มΘͬͯΔͷͰ஫ҙ͕ඞཁɻ array(3) { ["hoge.0"]=> string(5) "hoge0" ["hoge.1"]=>

    string(5) "hoge1" ["hoge.2"]=> string(5) "hoge2" } ※औಘྫ 26 $val->add('hoge.0'); 27 $val->add('hoge.1'); 28 $val->add('hoge.2'); 1.2.1 @wakuworks גࣜձࣾ 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ 12೥7݄8೔೔༵೔
  52. ͪͳΈʹɺϧʔϧ͸ݸผͰ͔͠ઃఆग़དྷͳ͍ 26 for ($i = 0; $i < 3; $i++)

    27 { 28 $val->add('hoge.'.$i)->add_rule('required'); 29 } 1.2.1 @wakuworks גࣜձࣾ 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ 12೥7݄8೔೔༵೔
  53. ͪͳΈʹɺϧʔϧ͸ݸผͰ͔͠ઃఆग़དྷͳ͍ 26 for ($i = 0; $i < 3; $i++)

    27 { 28 $val->add('hoge.'.$i)->add_rule('required'); 29 } ͱͯ΋໘౗͍͘͞… 1.2.1 @wakuworks גࣜձࣾ 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ 12೥7݄8೔೔༵೔
  54. ▾ fuel/ ▾ app/ ▸ cache/ ▸ classes/ ▸ config/

    ▸ lang/ ▸ logs/ ▸ migrations/ ▸ modules/ ▸ tasks/ ▸ tmp/ ▾ vendor/ ▾ Zend/ ▾ library/ ▾ Zend/ ▸ Date/ ▸ Filter/ ▸ Loader/ ▸ Locale/ ▸ Validate/ Date.php Exception.php Filter.php Loader.php Locale.php Registry.php Validate.php ▸ views/ bootstrap.php ▸ core/ ▸ packages/ LICENSE ▸ public/ αΠτ͔ΒιʔεҰࣜΛμ΢ϯϩʔυ ԼهΛࢀߟʹඞཁͳ෺͚ͩΛೖΕ·͢ɻ http://framework.zend.com/manual/ja/ requirements.introduction.html#requirement s.dependencies ※ ࠓճ͸ Ver. 1.11.12 Ͱઆ໌ ʢ2 ܥͰ΋Մʣ 1.2.1 @wakuworks גࣜձࣾ 4-4. Λ࢖͏ 12೥7݄8೔೔༵೔
  55. ▾ fuel/ ▾ app/ ▸ cache/ ▸ classes/ ▸ config/

    ▸ lang/ ▸ logs/ ▸ migrations/ ▸ modules/ ▸ tasks/ ▸ tmp/ ▾ vendor/ ▾ Zend/ ▾ library/ ▾ Zend/ ▸ Date/ ▸ Filter/ ▸ Loader/ ▸ Locale/ ▸ Validate/ Date.php Exception.php Filter.php Loader.php Locale.php Registry.php Validate.php ▸ views/ bootstrap.php ▸ core/ ▸ packages/ LICENSE ▸ public/ αΠτ͔ΒιʔεҰࣜΛμ΢ϯϩʔυ ԼهΛࢀߟʹඞཁͳ෺͚ͩΛೖΕ·͢ɻ http://framework.zend.com/manual/ja/ requirements.introduction.html#requirement s.dependencies ※ ࠓճ͸ Ver. 1.11.12 Ͱઆ໌ ʢ2 ܥͰ΋Մʣ 1.2.1 @wakuworks גࣜձࣾ 4-4. Λ࢖͏ 12೥7݄8೔೔༵೔
  56. 10 set_include_path(get_include_path() 11 .':'.APPPATH.'vendor/Zend/library/'); 12 13 Autoloader::add_classes(array( 14 // Add

    classes you want to override here 15 // Example: 'View' => APPPATH.'classes/view.php', 16 'Zend_Loader_Autoloader' => APPPATH 17 .'vendor/Zend/library/Zend/Loader/Autoloader.php', 18 )); 19 20 // Register the autoloader 21 Autoloader::register(); 22 Zend_Loader_Autoloader::getInstance(); APPPATH/bootstrap.php ͷಡΈࠐΈํ͸༷ʑ 1.2.1 @wakuworks גࣜձࣾ 4-4. Λ࢖͏ 12೥7݄8೔೔༵೔
  57. 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(array( 33 new Zend_Filter_StringTrim(), 34

    'filter' 35 )) 36 ->add_rule(array( 37 new Zend_Validate_Alpha(), 38 'isValid' 39 )); 1 <?php 2 return array( 3 'Zend_Validate_Alpha:isValid' 4 => ':labelΛਖ਼͘͠ೖྗ͍ͯͩ͘͠͞ɻ', 5 ); APPPATH/app/lang/ja/validation.php 1.2.1 @wakuworks גࣜձࣾ 4-4. Λ࢖͏ 12೥7݄8೔೔༵೔
  58. 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(array( 33 new Zend_Filter_StringTrim(), 34

    'filter' 35 )) 36 ->add_rule(array( 37 new Zend_Validate_Alpha(), 38 'isValid' 39 )); 1 <?php 2 return array( 3 'Zend_Validate_Alpha:isValid' 4 => ':labelΛਖ਼͘͠ೖྗ͍ͯͩ͘͠͞ɻ', 5 ); APPPATH/app/lang/ja/validation.php 1.2.1 @wakuworks גࣜձࣾ ϑΟϧλ 4-4. Λ࢖͏ 12೥7݄8೔೔༵೔
  59. 31 $val->add('id', 'Ϣʔβʔ ID') 32 ->add_rule(array( 33 new Zend_Filter_StringTrim(), 34

    'filter' 35 )) 36 ->add_rule(array( 37 new Zend_Validate_Alpha(), 38 'isValid' 39 )); 1 <?php 2 return array( 3 'Zend_Validate_Alpha:isValid' 4 => ':labelΛਖ਼͘͠ೖྗ͍ͯͩ͘͠͞ɻ', 5 ); APPPATH/app/lang/ja/validation.php 1.2.1 @wakuworks גࣜձࣾ ϑΟϧλ όϦσʔλ 4-4. Λ࢖͏ 12೥7݄8೔೔༵೔
  60. 24 $val = \Validation::forge(); 25 26 $val->add('name', '໊લ') 27 ->add_rule('trim')

    28 ->add_rule('required') 29 ->add_rule('max_length', 20); 30 31 $val->add_field('email', 'ϝʔϧΞυϨε', 32 'trim|required|valid_email'); 33 34 $val->add('submit', '', array( 35 'type' => 'submit', 36 'value' => '֬ೝ', 37 )); 38 39 $form_html = $val->fieldset() 40 ->build('/form/confirm/'); 41 $this->template->set_safe('form_html', $form_html); ※ Validation Ϋϥε͕࣋ͭ Fieldset ΠϯελϯεͰੜ੒ͯ͠Δ͚ͩ 1.2.1 @wakuworks גࣜձࣾ 5. ͓·͚ 12೥7݄8೔೔༵೔