Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Agenda CakePHP3 Ϩϙʔτ ࣮ࡍʹҊ݅Ͱ࠾༻ͨ͠ॴײ (ྑ͔ͬͨͱ͜Ζɺѱ͔ͬͨͱ͜Ζ) Model ( TableɺEntity ) 1. EntityͬͯԿʁ 2. Entity͸ศརͩͬͨʁ 3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ ࠓ·Ͱ$BLF1)1Λ࢖͍ͬͯͯɺ͜Ε͔Β$BLF1)1Λ࢖͏ํ޲͚ CakePHP2ͱͷൺֱ͕ͪΐͪ͜ΐ͜ɻɻɻɻ

Slide 4

Slide 4 text

1. EntityͬͯԿʁ 1. What is Entity?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

1. What is Entity? V C M CakePHP2 MVC of CakePHP2

Slide 9

Slide 9 text

1. What is Entity? V C T CakePHP3 E Table Entity MVC of CakePHP3

Slide 10

Slide 10 text

T 1. What is Entity? E ɾ$BLF1)1ͷʮ.PEFMʯʹ͍ۙ໾ׂ Table Entity ɾ%#ͷʮ5BCMFʯ΁ͷΞΫηε ɾσʔλϨίʔυ TableͱEntity ɾϨίʔυ͝ͱʹΠϯελϯεԽ ɾ഑ྻͰ͸ͳ͍ͷͰ֦ு͕༰қ ɾ7BMJEBUJPO Associationͷઃఆ

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

2. Entity͸ศརͩͬͨʁ 2. Is Entity useful ?

Slide 14

Slide 14 text

2. Is Entity useful ? 2. Entity͸ศརͩͬͨʁ 2-1. ॲཧ͕؆ܿʹͳͬͨ ɾFat Controller -> Fat Model -> ? 2-2. GetterͱSetter ɾ.7$ͷͲ͔͜ΒͰ΋ΞΫηεՄೳ

Slide 15

Slide 15 text

V C M Fat Controller ॳ৺ऀͷ͜Ζ 2. Is Entity useful ?

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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() Ͳ͔͜ΒͰ΋ΞΫηε

Slide 20

Slide 20 text

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()

Slide 21

Slide 21 text

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() Ͳ͔͜ΒͰ΋ΞΫηε

Slide 22

Slide 22 text

2. Is Entity useful ? Getter ྫ) ੏ͱ໊Λͭͳ͛ͯग़ྗ ̎ͭͷϑΟʔϧυΛͭͳ͛ͯग़ྗ ϑΟʔϧυʹॲཧΛՃ͑ͯग़ྗ ྫ) ֹۚΛ੫ࠐʹ ※ CakePHP2ͷafterFind()͕ෆཁʹͳΔ

Slide 23

Slide 23 text

2. Is Entity useful ? Setter ྫ) อଘ࣌ͷύεϫʔυΛϋογϡԽ ྫ) ੜ೥݄೔ͷอଘͱಉ࣌ʹ೥ྸ΋อଘ อଘ͢Δલͷ஋ͷมߋ ผϑΟʔϧυ΁ͷ஋ͷ௥Ճ ※ CakePHP2ͷbeforeSave()ͷهड़͕ݮΔ

Slide 24

Slide 24 text

2. Is Entity useful ? 2. Entity͸ศརͩͬͨʁ 1Ϋϥε͋ͨΓͷهड़ྔ͕ݮͬͨ ViewͰͷԋࢉࢠͷྔ͕ݮͬͨ ModelͷίʔϧόοΫͷهड़ྔ͕ݮͬͨ Fat EntityʹͳΒͳ͍ͨΊͷTips ڞ௨ॲཧ͸5SBJUԽʂ

Slide 25

Slide 25 text

3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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Λ࡞੒͢Δ࣌͸஫ҙ

Slide 28

Slide 28 text

3-2.ෳ਺ճ4FUUFS͕૸Δ ঢ়گ) ϚϧνεςοϓͷϑΥʔϜΛ࡞Γ͍ͨ Request Data Ma Form1 Form2 _setPassword() E adminadmin dsfknadfgnadflgkng Request Data Ma _setPassword() E dsfknadfgnadflgkng 32ekwnesihwenfansrueaf ͋Εʁ ※EntityͷઃఆΛมߋ͢Ε͹͍͍͕ɺ ɹɹ Marsherӽ͠Ͱ͸ઃఆΛมߋͰ͖ͳ͍

Slide 29

Slide 29 text

3. EntityͰϋϚͬͨͱ͜Ζ͋ͬͨʁ ҙਤ͍ͯ͠ͳ͍λΠϛϯάͰॲཧ͕૸Δ Entityͷઃఆ͸৮Γʹ͍͘ EntityҎ֎ͷ෦෼ͷམͱ݀͠͸͋·Γͳ͍

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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