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. FuelPHP ࣮ફ Validation
    FuelPHP ษڧձ ౦ژ Vol.1
    2012/07/08
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  2. ࣗݾ঺հ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  3. 1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  4. •ೋٶ ࿨ಙʢχϊϛϠ ΧζϊϦʣ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  5. •ೋٶ ࿨ಙʢχϊϛϠ ΧζϊϦʣ
    •Twitterɿ@wakuworks
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  6. •ೋٶ ࿨ಙʢχϊϛϠ ΧζϊϦʣ
    •Twitterɿ@wakuworks
    •גࣜձࣾ ಼
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  7. •ೋٶ ࿨ಙʢχϊϛϠ ΧζϊϦʣ
    •Twitterɿ@wakuworks
    •גࣜձࣾ ಼
    •PHP ྺ̏೥͘Β͍
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  8. ࣗ෼ʹͱͬͯ
    ͕
    ॳϑϨʔϜϫʔΫ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  9. ΞδΣϯμ
    1. جຊతͳ࢖͍ํ
    2. Τϥʔϝοηʔδ
    3. ϧʔϧʹ͍ͭͯ
    1. ಠࣗόϦσʔγϣϯ
    2. ಠࣗϑΟϧλ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  10. ΞδΣϯμ
    4. Ԡ༻
    1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ
    2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ
    3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    4. ZendFramework Λ࢖͏
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  11. ΞδΣϯμ
    5. ͓·͚
    6. ·ͱΊ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  12. 1. جຊతͳ࢖͍ํ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  13. 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೔೔༵೔

    View full-size slide

  14. 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೔೔༵೔

    View full-size slide

  15. 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೔೔༵೔

    View full-size slide

  16. run() ࣮ߦޙ
    1. جຊతͳ࢖͍ํ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  17. run() ࣮ߦޙ
    • $val->error() ͰɺݕূΤϥʔͷऔಘ
    1. جຊతͳ࢖͍ํ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  18. run() ࣮ߦޙ
    • $val->error() ͰɺݕূΤϥʔͷऔಘ
    • $val->validated() Ͱɺ੔ܗޙͷ஋ͷऔಘ
    ͨͩ͠ɺ్தͰݕূΤϥʔʹͳΔͱɺ
    ͦͷϑΟʔϧυͷ஋Λฦͯ͘͠Εͳ͍ɻ
    1. جຊతͳ࢖͍ํ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  19. 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೔೔༵೔

    View full-size slide

  20. 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೔೔༵೔

    View full-size slide

  21. 2. Τϥʔϝοηʔδ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

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

    View full-size slide

  23. 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೔೔༵೔

    View full-size slide

  24. σϑΥϧτͷΤϥʔϝοηʔδ
    Λ validation.php ʹઃఆ͓ͯ͘͠
    2. Τϥʔϝοηʔδ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  25. 2. Τϥʔϝοηʔδ
    1 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೔೔༵೔

    View full-size slide

  26. σϑΥϧτΛઃఆ͓ͯ͘͠ͱ
    ϞδϡʔϧΛ࡞ͬͨ࣌ʹศར
    2. Τϥʔϝοηʔδ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  27. APPPATH/modules/hoge/lang/ja/validation.php
    1 2 return array(
    3 'required' => 'hogeϞδϡʔϧ༻ͷΤϥʔϝοηʔδ',
    4 );
    ͜ͷ৔߹ɺrequired Ҏ֎ͷΤϥʔϝοηʔδ͸
    σϑΥϧτ͕࢖ΘΕΔɻ
    2. Τϥʔϝοηʔδ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  28. 3. ϧʔϧʹ͍ͭͯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  29. 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೔೔༵೔

    View full-size slide

  30. 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೔೔༵೔

    View full-size slide

  31. 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೔೔༵೔

    View full-size slide

  32. 3. ϧʔϧʹ͍ͭͯ
    ೋ௨Γͷϧʔϧ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  35. 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೔೔༵೔

    View full-size slide

  36. add_rule Ͱࢦఆग़དྷΔϧʔϧ
    3. ϧʔϧʹ͍ͭͯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  37. add_rule Ͱࢦఆग़དྷΔϧʔϧ
    • FuelPHP ଆͰ༻ҙ͍ͯ͠Δϧʔϧ
    3. ϧʔϧʹ͍ͭͯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  38. add_rule Ͱࢦఆग़དྷΔϧʔϧ
    • FuelPHP ଆͰ༻ҙ͍ͯ͠Δϧʔϧ
    • add_callable, add_model Ͱొ࿥ͨ͠ϧʔϧ
    3. ϧʔϧʹ͍ͭͯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

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

    View full-size slide

  40. 3. ϧʔϧʹ͍ͭͯ
    add_field Ͱࢦఆग़དྷΔϧʔϧ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  41. 3. ϧʔϧʹ͍ͭͯ
    add_field Ͱࢦఆग़དྷΔϧʔϧ
    • FuelPHP ଆͰ༻ҙ͍ͯ͠Δϧʔϧ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  42. 3. ϧʔϧʹ͍ͭͯ
    add_field Ͱࢦఆग़དྷΔϧʔϧ
    • FuelPHP ଆͰ༻ҙ͍ͯ͠Δϧʔϧ
    • add_callable, add_model Ͱొ࿥ͨ͠ϧʔϧ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

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

    View full-size slide

  44. • 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೔೔༵೔

    View full-size slide

  45. 3-1. ಠࣗόϦσʔγϣϯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  46. add_callable, add_model
    Λ༻͍Δ৔߹
    3-1. ಠࣗόϦσʔγϣϯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  47. 1 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೔೔༵೔

    View full-size slide

  48. 1 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೔೔༵೔

    View full-size slide

  49. 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 2 return array(
    3 'is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ',
    4 );
    12೥7݄8೔೔༵೔

    View full-size slide

  50. 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 2 return array(
    3 'is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ',
    4 );
    12೥7݄8೔೔༵೔

    View full-size slide

  51. 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 2 return array(
    3 'is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ',
    4 );
    12೥7݄8೔೔༵೔

    View full-size slide

  52. ϝιουΛ༻͍Δ৔߹
    3-1. ಠࣗόϦσʔγϣϯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  53. 1 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೔೔༵೔

    View full-size slide

  54. APPPATH/lang/ja/validation.php
    1 2 return array(
    3 'MyRules:is_upper' => ':label͸େจࣈͰೖྗ͍ͯͩ͘͠͞ɻ',
    4 );
    3-1. ಠࣗόϦσʔγϣϯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  55. ແ໊ؔ਺Λ༻͍Δ৔߹
    3-1. ಠࣗόϦσʔγϣϯ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  56. 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೔೔༵೔

    View full-size slide

  57. 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೔೔༵೔

    View full-size slide

  58. 3-2. ಠࣗϑΟϧλ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  59. ϝιουΛ༻͍Δ৔߹
    3-2. ಠࣗϑΟϧλ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  60. 3-2. ಠࣗϑΟϧλ
    1 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೔೔༵೔

    View full-size slide

  61. ແ໊ؔ਺Λ༻͍Δ৔߹
    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೔೔༵೔

    View full-size slide

  62. ݸਓతʹϑΟϧλΛ·ͱΊͨ
    Ϋϥε͕͋Δͱૉఢͩͱࢥ͏
    3-2. ಠࣗϑΟϧλ
    1.2.1 @wakuworks
    גࣜձࣾ
    ޙɺͦΕΛެ։ͯ͘͠ΕΔͱ΋ͬͱૉఢ
    12೥7݄8೔೔༵೔

    View full-size slide

  63. 3-2. ಠࣗϑΟϧλ
    1.2.1 @wakuworks
    גࣜձࣾ
    1 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೔೔༵೔

    View full-size slide

  64. 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೔೔༵೔

    View full-size slide

  65. 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೔೔༵೔

    View full-size slide

  66. 4. Ԡ༻
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  67. 4-1. ϑΟϧλʹΑΔฐ֐
    ͱͦͷରॲྫ
    4. Ԡ༻
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  68. match_field Ͱର৅ͷ
    ϑΟʔϧυʹϑΟϧλ͕
    ֻ͔͍ͬͯΔͱΤϥʔͱͳΔ
    ৔߹͕͋Δ
    4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  69. 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೔೔༵೔

    View full-size slide

  70. trim ޙɺಉ͡஋ʹͳΔʹ΋
    ؔΘΒͣΤϥʔ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ
    12೥7݄8೔೔༵೔

    View full-size slide

  71. Կނʁ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ
    12೥7݄8೔೔༵೔

    View full-size slide

  72. ൺֱ͕໰୊
    1.2.1 @wakuworks
    גࣜձࣾ
    4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ
    12೥7݄8೔೔༵೔

    View full-size slide

  73. 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೔೔༵೔

    View full-size slide

  74. 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೔೔༵೔

    View full-size slide

  75. ৽͍͠ϧʔϧΛ࡞Δ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ
    12೥7݄8೔೔༵೔

    View full-size slide

  76. 1 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೔೔༵೔

    View full-size slide

  77. 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೔೔༵೔

    View full-size slide

  78. 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೔೔༵೔

    View full-size slide

  79. 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೔೔༵೔

    View full-size slide

  80. 1 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೔೔༵೔

    View full-size slide

  81. ͜ΕͰϑΟϧλޙͷ஋Ͱ
    ൺֱΛͯ͘͠Ε·͢ɻ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-1. ϑΟϧλʹΑΔฐ֐ͱͦͷରॲྫ
    12೥7݄8೔೔༵೔

    View full-size slide

  82. 4-2. ಉ͡ϧʔϧͰ
    ෳ਺ͷΤϥʔϝοηʔδ
    4. Ԡ༻
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  83. ໊લͱੑผʹ required ͷϧʔϧΛઃఆ͍ͯͨ͠ͱͯ͠ɺ
    Լͷ༷ʹผʑͷΤϥʔϝοηʔδΛग़͍ͨ͠ͷ͚ͩͲ…
    required
    ໊લʢೖྗܥʣ→ʮ:labelΛೖྗ͍ͯͩ͘͠͞ɻʯ
    ੑผʢબ୒ܥʣ→ʮ:labelΛબ୒͍ͯͩ͘͠͞ɻʯ
    4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  84. validation.php ʹ
    ෳ਺ΤϥʔϝοηʔδΛ
    ઃఆ͢Δࣄ͸ग़དྷͳ͍
    1.2.1 @wakuworks
    גࣜձࣾ
    4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ
    12೥7݄8೔೔༵೔

    View full-size slide

  85. ࣮ࡍࣗ෼͕࢖͍ͬͯΔํ๏
    1.2.1 @wakuworks
    גࣜձࣾ
    4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ
    12೥7݄8೔೔༵೔

    View full-size slide

  86. 1 2 return array(
    3 'required' => ':labelΛೖྗ͍ͯͩ͘͠͞',
    4 );
    APPPATH/lang/ja/validation.php
    1 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೔೔༵೔

    View full-size slide

  87. 1 2 return array(
    3 'required' => ':labelΛೖྗ͍ͯͩ͘͠͞',
    4 );
    APPPATH/lang/ja/validation.php
    1 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೔೔༵೔

    View full-size slide

  88. 1 2 return array(
    3 'required' => ':labelΛೖྗ͍ͯͩ͘͠͞',
    4 );
    APPPATH/lang/ja/validation.php
    1 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೔೔༵೔

    View full-size slide

  89. 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೔೔༵೔

    View full-size slide

  90. 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೔೔༵೔

    View full-size slide

  91. 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೔೔༵೔

    View full-size slide

  92. ΋͏Ұͭํ๏͕͋Γ·͕͢ɺ
    ௕͍ͷͰׂѪ
    http://qiita.com/items/9d219b7300f851f9ba4f
    ↑ͪ͜Βʹιʔείʔυࡌ͍ͤͯΔͷͰɺ
    ࢼͯ͠Έ͍ͯͩ͘͞ɻ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ
    12೥7݄8೔೔༵೔

    View full-size slide

  93. ͋͘·Ͱ΋ࢀߟఔ౓ʹ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-2. ಉ͡ϧʔϧͰෳ਺ͷΤϥʔϝοηʔδ
    12೥7݄8೔೔༵೔

    View full-size slide

  94. 4-3. ഑ྻΛ
    όϦσʔτ͢Δʹ͸ʁ
    4. Ԡ༻
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  95. 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    14
    15
    16
    17
    18
    19
    ୯७ʹ name ΛೖΕͯ
    26 $val->add('hoge[0]');
    27 $val->add('hoge[1]');
    28 $val->add('hoge[2]');
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  96. 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    14
    15
    16
    17
    18
    19
    ୯७ʹ name ΛೖΕͯ
    RUN
    26 $val->add('hoge[0]');
    27 $val->add('hoge[1]');
    28 $val->add('hoge[2]');
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  97. 4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    14
    15
    16
    17
    18
    19
    ୯७ʹ name ΛೖΕͯ
    RUN
    ஋͕औΕͳ͍…
    26 $val->add('hoge[0]');
    27 $val->add('hoge[1]');
    28 $val->add('hoge[2]');
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  98. ໰୊͸ϑΟʔϧυ໊
    1.2.1 @wakuworks
    גࣜձࣾ
    4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    12೥7݄8೔೔༵೔

    View full-size slide

  99. υοτʢ.ʣͭͳ͗ͷ
    ϑΟʔϧυ໊ʹͯ͋͛͠Δ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    12೥7݄8೔೔༵೔

    View full-size slide

  100. 26 $val->add('hoge.0');
    27 $val->add('hoge.1');
    28 $val->add('hoge.2');
    1.2.1 @wakuworks
    גࣜձࣾ
    4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    12೥7݄8೔೔༵೔

    View full-size slide

  101. ͜ͷࢦఆํ๏͸ Config Ͱ༻͍͍ͯΔ΋ͷͱಉ͡ɻ
    ͝ஸೡʹΩʔ΋มΘͬͯΔͷͰ஫ҙ͕ඞཁɻ
    26 $val->add('hoge.0');
    27 $val->add('hoge.1');
    28 $val->add('hoge.2');
    1.2.1 @wakuworks
    גࣜձࣾ
    4-3. ഑ྻΛόϦσʔτ͢Δʹ͸ʁ
    12೥7݄8೔೔༵೔

    View full-size slide

  102. ͜ͷࢦఆํ๏͸ 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೔೔༵೔

    View full-size slide

  103. ͪͳΈʹɺϧʔϧ͸ݸผͰ͔͠ઃఆग़དྷͳ͍
    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೔೔༵೔

    View full-size slide

  104. ͪͳΈʹɺϧʔϧ͸ݸผͰ͔͠ઃఆग़དྷͳ͍
    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೔೔༵೔

    View full-size slide

  105. 4-4. Λ࢖͏
    4. Ԡ༻
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  106. ·ͣ͸४උ
    1.2.1 @wakuworks
    גࣜձࣾ
    4-4. Λ࢖͏
    12೥7݄8೔೔༵೔

    View full-size slide

  107. αΠτ͔ΒιʔεҰࣜΛμ΢ϯϩʔυ
    ԼهΛࢀߟʹඞཁͳ෺͚ͩΛೖΕ·͢ɻ
    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೔೔༵೔

    View full-size slide

  108. ▾ 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೔೔༵೔

    View full-size slide

  109. ▾ 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೔೔༵೔

    View full-size slide

  110. 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೔೔༵೔

    View full-size slide

  111. 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 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೔೔༵೔

    View full-size slide

  112. 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 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೔೔༵೔

    View full-size slide

  113. 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 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೔೔༵೔

    View full-size slide

  114. 5.͓·͚
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  115. Validation Ϋϥε͔Β
    ϑΥʔϜΛੜ੒ͯ͠ΈΔ
    5. ͓·͚
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  116. ઌʹݴ͏ͱ
    5. ͓·͚
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  117. શ͘໾ʹཱͪ·ͤΜɻ
    1.2.1 @wakuworks
    גࣜձࣾ
    5. ͓·͚
    12೥7݄8೔೔༵೔

    View full-size slide

  118. 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೔೔༵೔

    View full-size slide

  119. େਓ͘͠ Fieldset ͔Β
    ੜ੒ͨ͠ํ͕͍͍ͱࢥ͏
    1.2.1 @wakuworks
    גࣜձࣾ
    5. ͓·͚
    12೥7݄8೔೔༵೔

    View full-size slide

  120. 6. ·ͱΊ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide

  121. Validation Ұͭऔͬͯ΋࢖͍ํ͸༷ʑɻ
    ʮ͜Μͳํ๏͍͚Δͷʁʯͱࢼͨ͠ࣄ͕Ҋ
    ֎͢ΜͳΓͱ௨ͬͨΓɻ
    ͜͜·Ͱબ୒ࢶΛ༻ҙͯ͘͠Ε͍ͯΔ
    FuelPHP ΛɺվΊͯૉ੖Β͍͠ϑϨʔϜϫʔ
    Ϋͩͳͱײ͡·ͨ͠ɻ
    1.2.1 @wakuworks
    גࣜձࣾ
    6.·ͱΊ
    12೥7݄8೔೔༵೔

    View full-size slide

  122. Ҏ্ɺ
    ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ
    1.2.1 @wakuworks
    גࣜձࣾ
    12೥7݄8೔೔༵೔

    View full-size slide