Pro Yearly is on sale from $80 to $50! »

CakePHP3レポート

 CakePHP3レポート

PHPカンファレンス福岡2016での登壇資料

04052627dc708df299afd3aff44dde27?s=128

Junkins

May 26, 2016
Tweet

Transcript

  1. CakePHP3Ϩϙʔτ 2016/05/21 PHPΧϯϑΝϨϯε෱Ԭ ҏ౻ ५थ

  2. Introduction ҏ౻ ५थ Junkins_110 Junkins 1.3 2.ʙ 3.ʙ

  3. Agenda CakePHP3 Ϩϙʔτ ࣮ࡍʹҊ݅Ͱ࠾༻ͨ͠ॴײ (ྑ͔ͬͨͱ͜Ζɺѱ͔ͬͨͱ͜Ζ) Model ( TableɺEntity ) 1.

    EntityͬͯԿʁ 2. Entity͸ศརͩͬͨʁ 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ ࠓ·Ͱ$BLF1)1Λ࢖͍ͬͯͯɺ͜Ε͔Β$BLF1)1Λ࢖͏ํ޲͚ CakePHP2ͱͷൺֱ͕ͪΐͪ͜ΐ͜ɻɻɻɻ
  4. 1. EntityͬͯԿʁ 1. What is Entity?

  5. 1. EntityͬͯԿʁ 1-1. MVC 1-2. TableͱEntity 1-3. Entityͷొ৔γʔϯ 1. What

    is Entity?
  6. 1. What is Entity? V C M MVC Model View

    Controller View Controller Model
  7. 1. What is Entity? MVC Model View Controller V C

    M View Controller Model
  8. 1. What is Entity? V C M CakePHP2 MVC of

    CakePHP2
  9. 1. What is Entity? V C T CakePHP3 E Table

    Entity MVC of CakePHP3
  10. T 1. What is Entity? E ɾ$BLF1)1ͷʮ.PEFMʯʹ͍ۙ໾ׂ Table Entity ɾ%#ͷʮ5BCMFʯ΁ͷΞΫηε

    ɾσʔλϨίʔυ TableͱEntity ɾϨίʔυ͝ͱʹΠϯελϯεԽ ɾ഑ྻͰ͸ͳ͍ͷͰ֦ு͕༰қ ɾ7BMJEBUJPO Associationͷઃఆ
  11. 1. What is Entity? E Entityͷొ৔γʔϯ E E E E

    E E E E E E E E E E E E E E E E E E E E E Ma Request Data DB ResultSet Marshaller beforeMarshal() Validation() SELECT SELECT
  12. 1. EntityͬͯԿʁ Entity͸CakePHP2Ͱ͍͏ModelͷҰ෦෼ CakePHP2ͷModel͸TableͱEntityʹ෼͔Εͨ find(SELECT)ͨ͠ͱ͖ + POST͞Εͨͱ͖ POST͞ΕͨσʔλΛEntityԽ͢Δͱ͖ʹόϦσʔγϣϯ͕ಈ͘ ( CakePHP2ͱಉ༷ʹอଘ࣌ʹ΋όϦσʔγϣϯ͸ಈ͘

    ) 1. What is Entity?
  13. 2. Entity͸ศརͩͬͨʁ 2. Is Entity useful ?

  14. 2. Is Entity useful ? 2. Entity͸ศརͩͬͨʁ 2-1. ॲཧ͕؆ܿʹͳͬͨ ɾFat

    Controller -> Fat Model -> ? 2-2. GetterͱSetter ɾ.7$ͷͲ͔͜ΒͰ΋ΞΫηεՄೳ
  15. V C M Fat Controller ॳ৺ऀͷ͜Ζ 2. Is Entity useful

    ?
  16. V C M Fat Model খ׳Ε͖ͯͨ͜Ζ 2. Is Entity useful

    ?
  17. V C M T E Finder Validation Association Save 2.

    Is Entity useful ? ͜ͷ͝Ζ μΠΤοτ
  18. V C M T E μΠΤοτ Finder Validation Association Save

    2. Is Entity useful ? ͜ͷ͝Ζ
  19. 2. Is Entity useful ? V C M E CakePHP3

    E E E function hoge() V C M CakePHP2 V C M array( ) array( ) array( ) function hoge() Ͳ͔͜ΒͰ΋ΞΫηε
  20. 2. Is Entity useful ? V C M E Ͳ͔͜ΒͰ΋ΞΫηε

    CakePHP3 E E E function hoge() V C M CakePHP2 V C M array( ) array( ) array( ) function hoge() hoge() hoge() hoge()
  21. 2. Is Entity useful ? V C M E CakePHP3

    E E E function hoge() V C M CakePHP2 V C M array( ) array( ) array( ) function hoge() hoge() hoge() Ͳ͔͜ΒͰ΋ΞΫηε
  22. 2. Is Entity useful ? Getter ྫ) ੏ͱ໊Λͭͳ͛ͯग़ྗ ̎ͭͷϑΟʔϧυΛͭͳ͛ͯग़ྗ ϑΟʔϧυʹॲཧΛՃ͑ͯग़ྗ

    ྫ) ֹۚΛ੫ࠐʹ ※ CakePHP2ͷafterFind()͕ෆཁʹͳΔ
  23. 2. Is Entity useful ? Setter ྫ) อଘ࣌ͷύεϫʔυΛϋογϡԽ ྫ) ੜ೥݄೔ͷอଘͱಉ࣌ʹ೥ྸ΋อଘ

    อଘ͢Δલͷ஋ͷมߋ ผϑΟʔϧυ΁ͷ஋ͷ௥Ճ ※ CakePHP2ͷbeforeSave()ͷهड़͕ݮΔ
  24. 2. Is Entity useful ? 2. Entity͸ศརͩͬͨʁ 1Ϋϥε͋ͨΓͷهड़ྔ͕ݮͬͨ ViewͰͷԋࢉࢠͷྔ͕ݮͬͨ ModelͷίʔϧόοΫͷهड़ྔ͕ݮͬͨ

    Fat EntityʹͳΒͳ͍ͨΊͷTips ڞ௨ॲཧ͸5SBJUԽʂ
  25. 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ

  26. 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ 1. อଘ࣌ʹ(FUUFS͕૸Δ 2. ෳ਺ճ4FUUFS͕૸Δ

  27. 3-1.อଘ࣌ʹ(FUUFS͕૸Δ ঢ়گ) ֹۚΛද͍ࣔͨ͠ʂJOQVUͷ஋΋ΧϯϚ۠੾Γʹ͍ͨ͠ʂ 1000 int text 1,000 text 1,000 1000

    int 1000 int text 1,000 1000 int text1,000 text 1,000 1000 int Getter Setter Getter Setter Getter ཧ૝ ݱ࣮ SQL Error ※ ΧϥϜ໊Ͱ(FUUFSΛ࡞੒͢Δ࣌͸஫ҙ
  28. 3-2.ෳ਺ճ4FUUFS͕૸Δ ঢ়گ) ϚϧνεςοϓͷϑΥʔϜΛ࡞Γ͍ͨ Request Data Ma Form1 Form2 _setPassword() E

    adminadmin dsfknadfgnadflgkng Request Data Ma _setPassword() E dsfknadfgnadflgkng 32ekwnesihwenfansrueaf ͋Εʁ ※EntityͷઃఆΛมߋ͢Ε͹͍͍͕ɺ ɹɹ Marsherӽ͠Ͱ͸ઃఆΛมߋͰ͖ͳ͍
  29. 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ ҙਤ͍ͯ͠ͳ͍λΠϛϯάͰॲཧ͕૸Δ Entityͷઃఆ͸৮Γʹ͍͘ EntityҎ֎ͷ෦෼ͷམͱ݀͠͸͋·Γͳ͍

  30. ·ͱΊ EntityΛ࢖͍͜ͳͤΕ͹ɺޮ཰తͳ։ൃ͕Մೳ TableɺEntity͕෼͔Εͯɺඇৗʹॻ͖΍͍͢ Entity͸ඇৗʹศརͰCakePHP3Λ࢖͏ͳΒੋඇཧղͯ͠΄͍͠ Entity͸ศརͳ෼ɺཧղͯ͠࢖Θͳ͍ͱམͱ͕݀͋͠Γ·͢ PluginΛ࡞Δͱ͖͸Entityͷಈ͖ʹؾΛ͚ͭͳ͍ͱ͍͚ͳ͍

  31. ͍͞͝ʹ Fusic͸ςΫϊϩδʔ͕ ޷͖ͳΤϯδχΞΛืू͍ͯ͠·͢ https://fusic.github.io

  32. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ