Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
EC-CUBE3コードリーディング #4
Search
amidaike
March 02, 2016
Programming
1.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
EC-CUBE3コードリーディング #4
amidaike
March 02, 2016
More Decks by amidaike
See All by amidaike
EC-CUBE3勉強会新しいデザインを作成してみよう
amidaike
0
490
EC-CUBE 3.0勉強会
amidaike
1
1k
EC-CUBE3プラグイン勉強会
amidaike
0
490
EC-CUBE3デザイナー向け勉強会 #4
amidaike
0
330
EC-CUBE3コードリーディング #5
amidaike
1
1.6k
EC-CUBE3デザイナー向け勉強会 #1
amidaike
0
310
EC-CUBE3デザイナー向け勉強会 #3
amidaike
1
240
EC-CUBE3デザイナー向け勉強会 #2
amidaike
1
2.8k
EC-CUBE3コードリーディング #3
amidaike
1
980
Other Decks in Programming
See All in Programming
ActionController meets Protocol Buffers
sorah
0
360
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
210
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.1k
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
380
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
170
mrbgem 三角測量 開発
ogom
0
240
R8 の設定見直しでアプリサイズ削減
andpad
0
210
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
990
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
22
22k
ChromeでローカルLLM
ryu1013
0
130
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
3
2.2k
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
700
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
730
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Between Models and Reality
mayunak
4
490
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Building AI with AI
inesmontani
PRO
1
1.3k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Transcript
EC-CUBE3ίʔυϦʔσΟϯά #4 EC-CUBEؔϢʔβάϧʔϓ 2016-03-02
࣍ 1. Doctrineͷ֓ཁ 2. DoctrineΛͬͨςʔϒϧఆٛ 3. DoctrineΛͬͨDBΞΫηε RepositoryɺfindϝιουɺDQLͷઆ໌ 4. EC-CUBE3ίʔυϦʔσΟϯά
ཧը໘ͷཧ 5. ࣭ٙԠ
1.Doctrineͷ֓ཁ
Doctrineͷ֓ཁ • DoctrineͱPHPͰॻ͔ΕͨO/RϚούʔͰ͢ɻ • ͏গ͠ݫີʹઆ໌͢ΔͱDoctrinePDOΛར༻ͨ͠ҎԼͷओཁͳϥΠϒϥϦͰߏ͞ Ε͓ͯΓɺ૯শͱͯ͠ҰൠతʹO/RϚούʔͱݺΕ͍ͯ·͢ɻ DoctrineCommon : ڞ௨ϥΠϒϥϦ DoctrineDBAL
: ֤DBMSͷࠩΛٵऩ͢ΔϨΠϠʔ DoctrineORM : O/RϚούʔ • ORM(Object Relational Mapping)ͱϓϩάϥϛϯάݴޠͷςΫχοΫͰ͋Γɺσʔλ ϕʔεͱΦϒδΣΫτࢦϓϩάϥϛϯάݴޠͷؒͷඇޓͳσʔλΛม͢Δϓϩά ϥϛϯάٕ๏Ͱ͢ɻMySQLͷσʔλϕʔεͷσʔλΛૢ࡞͍͢͠Α͏ʹ PHP Φϒ δΣΫτʹม͠·͢ɻ • DBAL(Database Abstraction Layer)ͱPDOͷநϨΠϠʔͰɺσʔλϕʔεͱΓऔ Γ͢ΔAPIΛఏڙ͠·͢ɻ
2.DoctrineΛͬͨςʔϒϧఆٛ
DoctrineΛͬͨςʔϒϧఆٛ • ຊདྷσʔλϕʔεͷςʔϒϧΛ࡞͢Δʹcreate tableจͰSQLจΛͬͯ࡞͠· ͕͢ɺDoctrineRuby on Rails༝དྷͷmigrationػೳΛͬͯσʔλϕʔεཧΛ͠· ͢ɻ • ࣮ࡍʹҎԼͷखॱΛͬͯςʔϒϧΛ࡞͠·͢ɻ
1.ϝλσʔλͱݺΕΔઃఆϑΝΠϧ(xxxx.dcm.yml)ʹςʔϒϧΛఆٛ ˠECCUBEROOT/src/Eccube/Resource/doctrine ʹଘࡏ 2.ymlϑΝΠϧʹରԠ͢ΔΤϯςΟςΟΫϥεΛ࡞ ˠECCUBEROOT/src/Eccube/Entity ʹଘࡏ 3.doctrine migrationػೳΛͬͯσʔλϕʔεʹద༻ ˠymlϑΝΠϧͱEntityΛͱʹςʔϒϧ࡞ɺmigration࣌ͷόʔδϣϯཧ༻ςʔ ϒϧ࡞ 4.ςʔϒϧʹมߋ͕ೖΕɺ1ɺ2ɺ3ͷखॱΛ܁Γฦͯ͠σʔλϕʔεʹద༻
ςʔϒϧΛ࡞͠Α͏ • ຊମʹରͯ͠ςʔϒϧΛ࡞͢Δ͜ͱ͋Γ·ͤΜ͕ɺࠓޙ ͷͨΊʹςʔϒϧͷ࡞ํ๏Λઆ໌͓͖ͯ͠·͢ɻ • ςʔϒϧΛ࡞͢ΔͨΊʹඞཁͳϑΝΠϧɺ dcm.ymlϑΝΠϧ (ςʔϒϧఆٛͨ͠ymlϑΝΠϧ) EntityΫϥε (ςʔϒϧΛදͨ͠phpΫϥε)
͕࠷ݶඞཁͱͳΓ·͢ɻ • RepositoryΫϥε (ςʔϒϧʹΞΫηε͢ΔΫϥε)ࠓճ ͋ͬͯͳͯ͘ߏ͍·ͤΜ͕ɺEC-CUBE3Ͱඞͣ࡞͠ ͍ͯ·͢ɻ
ςʔϒϧΛ࡞͠Α͏ • ECCUBEROOT/src/Eccube/Resource/doctrine Լʹ Eccube.Entity.Study.dcm.yml ϑΝΠϧΛ࡞͠·͢ɻ • dcm.ymlϑΝΠϧΛ࡞ޙɺEntityΫϥεΛdoctrineί ϚϯυΛͬͯ࡞͠·͢ɻ(શͯ1ߦͰهड़) vendor/bin/doctrine
orm:generate:entities --extend="Eccube \\Entity\\AbstractEntity" src
ςʔϒϧΛ࡞͠Α͏ • Eccube.Entity.Study.dcm.ymlͷ༰ Eccube\Entity\Study: type: entity table: dtb_study repositoryClass: Eccube\Repository\StudyRepository
id: id: type: integer nullable: false id: true column: study_id generator: strategy: AUTO options: unsigned: true fields: name: type: string length: 100 url: type: string nullable: true length: 200 create_date: type: datetime nullable: false update_date: type: datetime nullable: false lifecycleCallbacks: { }
ςʔϒϧΛ࡞͠Α͏ • EntityΫϥεΛ࡞ޙɺ࣮ࡍʹMySQLPostgresʹରͯ͠ςʔϒϧ Λ࡞͠·͢ɻ࡞ํ๏2௨Γ͋ΓɺmigrationͱݺΕΔ ΈΛ͏͔ɺdoctrineίϚϯυΛͬͯςʔϒϧΛ࡞͢Δ͔ͷ2 ௨Γ͋Γ·͢ɻࠓճ͕࣌ؒͳ͍ͨΊdoctrineίϚϯυΛ͏ํ๏ Λઆ໌͠·͢ɻ
ɾDBͷϚΠάϨʔγϣϯํ๏ vendor/bin/doctrine orm:schema-tool:update Λ࣮ߦͯ͠migrationՄೳ͔Ͳ͏͔Λ֬ೝ͢Δɻ vendor/bin/doctrine orm:schema-tool:update --dump-sql Λ࣮ߦͯ͠sqlΛ֬ೝ vendor/bin/doctrine orm:schema-tool:update --force Λ࣮ߦͯ͠DBϚΠάϨʔγϣϯ
3.DoctrineΛͬͨDBΞΫηε
DoctrineΛͬͨDBΞΫηε • DBʹΞΫηε͢ΔͨΊʹRepositoryͱݺΕΔΫϥεΛ͍·͢ɻ • RepositoryಛఆͷΫϥεͷΤϯςΟςΟͷݕࡧΛิॿ͢ΔͨΊ͚ͩͷ PHPΫϥεͰ͢ɻࢦఆ͞ΕͨΤϯςΟςΟΛऔಘ͢ΔͨΊʹRepository Λ͍·͢ɻ • ymlϑΝΠϧʹrepositoryClass: Eccube\Repository\XXXXRepositoriͱ
هड़͠ͳ͚ΕσϑΥϧτͰDoctrine\ORM\EntityRepositoryΫϥε ͕ར༻͞Ε·͢ɻ Eccube\Entity\Product: type: entity table: dtb_product repositoryClass: Eccube\Repository\ProductRepository ← ͜ΕͰ͢
DoctrineΛͬͨDBΞΫηε • EC-CUBE3ͰRepositoryΤϯςΟςΟΫϥεຖʹରԠ͢Δ RepositoryΫϥεΛ༻ҙ͠ɺͦͷRepository Doctrine\ORM\EntityRepositoryΫϥεΛܧঝͯ͠࡞͠·͢ɻ • RepositoryΛݺͼग़͢ͱ͖ɺ $app['orm.em']->getRepository('Eccube\Entity\XXXX') ͱ͢Δ͜ͱͰRepositoryΛݺͼग़͠ɺRepositoryΫϥε͕༻ҙ͍ͯ͠Δ ϝιουͰDBʹΞΫηε͠·͢ɻ
• EC-CUBE3ͰRepositoryΫϥεશͯ$appʹDI͍ͯ͠·͢ɻ (ECCUBEROOT/src/Eccube/ServiceProvider/ EccubeServiceProvider.phpΛࢀর)
DoctrineΛͬͨDBΞΫηε • EntityRepositoryΫϥεʹඪ४Ͱ༻ҙ͞Ε͍ͯΔศརͳϝ ιου͕͋Γ·͢ɻΑ͘͏ϝιουʹҎԼͷͷ͕͋Γ ·͢ɻ find : ओΩʔΛݩʹݕࡧ݁ՌΛऔಘ findAll :
શ݅औಘ findBy : ͋Δ݅Λݩʹݕࡧ findOneBy : ͋Δ݅Λݩʹݕࡧ͢Δ͕݁Ռ1݅ͷΈ • ͬͱෳࡶͳ͕݅ඞཁͳ߹ɺ֤RepositoryΫϥεʹϝ ιουΛՃ͍ͯͩ͘͠͞ɻ
DoctrineΛͬͨDBΞΫηε • findϝιου ݕࡧ݁ՌओΩʔʹ֘͢Δ1݅ͷΈͰɺRepositiryʹ ؔ͢ΔEntityΫϥε͕औಘͰ͖·͢ɻ $Product = $app['eccube.repository.product'] ->find($id);
DoctrineΛͬͨDBΞΫηε • findAllϝιου ݕࡧ݁Ռશ݅औಘ͞ΕɺEntityΫϥεͷྻ(array)͕ औಘͰ͖·͢ɻ $Products = $app['eccube.repository.product'] ->findAll();
DoctrineΛͬͨDBΞΫηε • findByϝιου ࢦఆͨ͠ݕࡧ݅Λݩʹݕࡧ͠ɺ֘͢Δ݅ͷEntity Ϋϥεͷྻ(array)͕औಘͰ͖·͢ɻ $Products = $app['eccube.repository.product'] ->findBy( array(
'name' => 'hoge', 'xxxx' => 'yyyyy' ) );
DoctrineΛͬͨDBΞΫηε • findOneByϝιου ࢦఆͨ͠ݕࡧ݅Λݩʹݕࡧ͠ɺ֘͢Δ݅ͷEntity Ϋϥε1݅ͷΈ͕औಘͰ͖·͢ɻ $Product = $app['eccube.repository.product'] ->findOneBy( array(
'name' => 'hoge', 'xxxx' => 'yyyyy' ) );
DoctrineΛͬͨDBΞΫηε • ιʔτ݅ findByɺfindOneByϝιουݕࡧ݅ࢦఆҎ֎ʹιʔ τ݅ࢦఆͰ͖·͢ɻ $Products = $app['eccube.repository.product'] ->findBy( array('name'
=> 'hoge'), array('update_date' => 'DESC') );
DoctrineΛͬͨDBΞΫηε • RepositoryΫϥεʹ༻ҙ͞Ε͍ͯΔfindϝιουͳͲΛ͑جຊతͳΫΤϦͰ ͋Ε؆୯ʹDB͔ΒΛऔಘ͢Δ͜ͱ͕ग़དྷ·͕ͨ͠ɺΑΓෳࡶͳΫΤϦѻ ͏͜ͱ͕Ͱ͖·͢ɻ • ΑΓෳࡶͳΫΤϦΛѻ͏߹ɺDQL(Doctrine Query Language) Λ༻ͯ͠ॻ͘
͜ͱՄೳͰ͢ɻDQLSQLͱࣅ͍ͯ·͕͢ɺςʔϒϧ(ྫ: product)ͷߦͰͳ ͯ͘ɺ1ͭҎ্ͷΤϯςΟςΟΫϥεΦϒδΣΫτ(ྫ: Product)ʹରͯ͠ΫΤϦ ͢Δͱ͍͏͜ͱΛఆ͠·͢ɻ • DoctrineͰΫΤϦ͢Δʹ2ͭͷબࢶ͕͋Γ·͢ɻ७ਮͳDoctrineΫΤϦΛॻ ͔͘ɺDoctrineͷQueryBuilderΛ༻͢Δ͜ͱͰ͢ɻ http://docs.symfony.gr.jp/symfony2/book/doctrine.html#book-doctrine-queries
DoctrineΛͬͨDBΞΫηε • DoctrineΫΤϦSQLจʹඇৗʹΑ͘ࣅͨ༰Ͱهड़͢ Δ͜ͱ͕ՄೳͰ͢ɻ • SQLʹ׳Ε͍ͯͨ߹ɺDoctrineΫΤϦΛ͙͑͢ʹ ѻ͏͜ͱ͕ՄೳͰ͢ɻ • DoctrineͷQueryBuilderΛ͑ɺΦϒδΣΫτࢦ ͳΠϯλʔϑΣʔεΛͬͯهड़͢Δ͜ͱ͕ՄೳͰ͢ɻ
• QueryBuilderΦϒδΣΫτɺΫΤϦΛΈཱͯΔͷ ʹඞཁͳϝιουશͯΛؚΜͰ͍·͢
DoctrineΛͬͨDBΞΫηε • DoctrineΫΤϦͷྫ DoctrineΫΤϦΛ͏ͱ΄΅SQLͱಉ༷ͷ༰Ͱهड़͕ ग़དྷ·͢ɻ $query = $app['eccube.repository.product'] ->createQuery( 'SELECT
p FROM Eccube\Entity\Product p WHERE p.name = :name ORDER BY p.update_date DESC' ) ->setParameter('name', 'hoge'); $Products = $query->getResult();
DoctrineΛͬͨDBΞΫηε • QueryBuilderͷྫ QueryBuilderΛ͏ͱɺෳࡶͳ݅Λهड़͢Δ͜ͱ͕ ՄೳͰɺΫΤϦͰΈཱͯΔͷʹඞཁͳϝιου (whereɺorderByɺetc...)͕શͯ͋Γ·͢ɻ $query = $app['eccube.repository.product'] ->createQueryBuilder('p')
->where('p.name = :name') ->orderBy('p.update_date', 'DESC'); ->setParameter('name', 'hoge') ->getQuery(); $Products = $query->getResult();
4.EC-CUBE3ίʔυϦʔσΟϯά
EC-CUBE3ίʔυϦʔσΟϯά • AdminσΟϨΫτϦԼʹཧը໘༻ίϯτϩʔ ϥʔ͕ଘࡏ σΟϨΫτϦ໊ ػೳ໊ AdminController ϩάΠϯը໘ɺཧը໘τοϓ Content ίϯςϯπཧ༻
Customer ձһཧ༻ Order डཧ༻ Product ཧ༻ Setting جຊใઃఆɺγεςϜใઃఆ༻ Store ΦʔφʔζετΞ༻
EC-CUBE3ίʔυϦʔσΟϯά • Admin\Product\ProductController.phpͷίʔυϦʔσ Οϯά
5.࣭ٙԠ
։ൃ࣌ͷࢀߟϖʔδ • GitHubWiki https://github.com/EC-CUBE/ec-cube/wiki • GitHubPages http://ec-cube.github.io • Qiitaͷهࣄ http://qiita.com/tags/EC-CUBE3