MVCãã¬ã¼ã ã¯ã¼ã¯ã§Webã¢ããªã±ã¼ã·ã§ã³ãä½æããã¨ããè¥å¤§åãã¦ããã¢ãã«ãã©ã®ããã«åå²ããã°è¯ãã®ãï¼æ©ã¿ã¾ãã
ãã¤ãã¯é©å½ã«ãã£ã¦ããã®ã§ãããã ãã ããã¡ã¤ã«æ°ãã¯ã©ã¹æ°ãã¡ã½ããæ°ãå¢ãã¦ããã¨ãææ¡ãã¥ãããªã£ã¦ãè¾ããªã£ã¦ãã¾ãï½
ä»ã®äººã®ããæ¹ãåèã«ãã¦ãã¢ãã«ãé©åã«åå²ããæ¹æ³ãæ¤è¨ãã¦ã¿ã¾ããã
Â
âWebã¢ããªã¨ã¯ï¼
Webã¢ããªã®ç¹å¾´ã¯ãã¤ã³ã¿ã¼ããããã¯ããã§ã
(1) ã¯ã©ã¤ã¢ã³ãå´
(2) ãµã¼ãã¼å´
ã«åããã¦ãããã¨ã§ãã
Â
ãµã¼ãã¼å´ã¯ã
(a) DBï¼ãã¼ã¿ãç½®ãã¦ããå ´æãé常ã¯ãªã¬ã¼ã·ã§ãã«ãã¼ã¿ãã¼ã¹ï¼
(b) DBã®ã©ããã¼ï¼CRUDãæ å½ããã¢ããªã±ã¼ã·ã§ã³å±¤ï¼
ã«åããã¦ãã¾ãã
ã§ããã®ã©ããã¼é¨å(b)ã«ãMVCãã¬ã¼ã ã¯ã¼ã¯ã使ã£ã¦ãã¾ãã
Â
(via ãã¿ãé¥ é ï¼ããããï¼ï¼ãã¿ãé¥ é ã®ãã¾ã å±)
Â
MVCãã¬ã¼ã ã¯ã¼ã¯ã¯ã
(M) Model ⦠ãã¼ã¿ã®å¦ç
(V) View ⦠表示æ©è½
(C) Controller ⦠å¦çãæ¯åããå¸ä»¤å¡ï¼dispatcherï¼
ã«åããã¦ãã¾ãã
ä¸è¬çã«ããã¼ã¿ã®å¦çï¼ãã¸ãã¯ï¼ã¯ãã³ã³ããã¼ã©ã¼ã«æ¸ããªãã§ãã¢ãã«ã«æ¸ããã¨ãæ¨å¥¨ããã¦ãã¾ãã
Â
Â
ã»èãã³ã³ããã¼ã©ã¼ãåãã¢ãã«
ã»ãã¼ã¿å å·¥å¦çã¯ã¢ãã«ã«æ å½ããã
ã»ã³ã³ããã¼ã©ã¼ãã·ã³ãã«ã«ãã
ãå¦çã®æµãããããããããªã
Â
âã¢ãã«é¨åã®åå²
ã¢ãã«ã«ããã°ã©ã ã®ã³ã¼ããæ¸ãã¦ããã¨ãã¢ãã«ãè¥å¤§åãã¦ãã³ã¼ããèªã¿ã¥ãããªãã¾ãã
è¥å¤§åããã¢ãã«ãåå²ããæ¹æ³ããã¿ã¼ã³ãããããèæ¡ããã¦ãã¾ãã
Â
ãã¡ã¤ã³é§åè¨è¨ - Wikipedia
ãã¡ã¤ã³é§åè¨è¨ï¼Domain-driven design, DDDï¼ã¨ã¯ã½ããã¦ã§ã¢ã®è¨è¨ææ³
Â
å®è·µãã¡ã¤ã³é§åè¨è¨ (Object Oriented SELECTION)
- ä½è : ã´ã¡ã¼ã³ã»ã´ã¡ã¼ãã³,é«æ¨æ£å¼
- åºç社/ã¡ã¼ã«ã¼: ç¿æ³³ç¤¾
- çºå£²æ¥: 2015/03/17
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã°ãè¦ã
Â
Â
âã¬ã¤ã¤ã¼ï¼é層ï¼ã®å°å ¥
ã³ã³ãã¥ã¼ã¿ã¼ãããã¯ã¼ã¯ã®ãOSIåç §ã¢ãã«ãã®ããã«ãè¤éãªå¦çã¯ãæ©è½ãåå²ããã¨è¦éããè¯ããªãã¾ããï¼
MVCã®ã¢ãã«ãããã¼ã¿å¦çã®æ®µéã«å¿ãã¦ãé層ãåããè¨è¨ãæå±ããã¦ãã¾ããã
Â
Â
ã»ã³ã³ããã¼ã©ã¼ã¨DBã®éã®ã¢ãã«ã¯ããServiceãã¨ãDAOãã®2層ã«åå²ããã¦ããã
ã»ãServiceãâ¦ãã¸ãã¹ãã¸ãã¯ãæ å½
ã»ãDAOãâ¦ãã¼ã¿ã¢ã¯ã»ã¹ãæ å½
Â
å ¥åããåºåã¾ã§ã®æµãã§è¡¨ç¾ããã¨ã次ã®å³ã®ããã«ãªãã
æ´æ°ç³»ã®å¦çãä¾ã«ãã·ã¼ã±ã³ã¹ã説æããã
1. ControllerããRequestãåãä»ãã
2. (Optional) Controllerã¯ãHelperãå¼ã³åºããFormã®æ å ±ããDomain Objectã¾ãã¯DTOã«å¤æãã
3. Controllerã¯ãDomain Objectã¾ãã¯DTOãç¨ãã¦ãServiceãå¼ã³åºã
4. Serviceã¯ãRepositoryãå¼ã³åºãã¦ãæ¥åå¦çãè¡ã
5. Repositoryã¯ãO/R Mapperãå¼ã³åºããDomain Objectã¾ãã¯DTOãæ°¸ç¶åãã
6. (å®è£ ä¾å) O/R Mapperã¯ãDBã«Domain Objectã¾ãã¯DTOã®æ å ±ãä¿åãã
7. Serviceã¯ãæ¥åå¦ççµæã®Domain Objectã¾ãã¯DTOããControllerã«è¿å´ãã
8. (Optional) Controllerã¯ãHelperãå¼ã³åºããDomain Objectã¾ãã¯DTOããFormã«å¤æãã
9. Controllerã¯ãé·ç§»å ã®Viewåãè¿å´ãã
10. Viewã¯ãResponseãåºåããã
ã¢ãã«ã®é¨åãã
ã»Service
ã»Repository
ã»O/R Mapper
ã®3層ã«åå²ãã¦ãå½¹å²åæ ããã¦ãããã§ããã
Â
Repositoryãä½æãããã¨ã«ãããæ°¸ç¶åæè¡ãé è½ã§ãããããã¼ã¿ã¢ã¯ã»ã¹å¦çãå ±éåã§ãããªã©ã®ã¡ãªãããããã
ãã¼ã¿ã¢ã¯ã»ã¹ã®æ½è±¡åãå¿ è¦ãªãã®ã§ããã°ãRepositoryã¯ä½æããã以ä¸ã®å³ã®ããã«ãServiceããç´æ¥O/R Mapperãå¼ã³åºãããã«ããã°ããã
Â
ã¢ãã«ã®é¨åãã2層ã¨ã3層ã«ç´°ååãã¦ãå½¹å²åæ ããããã¨ãã§ãã¾ãã
Â
âCodeIgniterã®å ´å
CodeIgniterï¼PHPã®MVCãã¬ã¼ã ã¯ã¼ã¯ï¼ã§ã¯ãã¢ãã«ããã¢ãã«ãå¼ã³åºããã¨ãå¯è½ã§ããï¼ã¢ãã«ãç´°ååãã¦ãåå©ç¨ãããã¨ãå¯è½ã
Â
ã»ã¢ãã«ã3層ã«åå²ãã¦ãå½¹å²åæ ãããã
ã»æ±ç¨æ§ã®é«ããåå©ç¨å¯è½ãªã¡ã½ãããç¨æããã
ã¨ãããã¨ãå®ç¾ããããã«ã以ä¸ã®ãããªæ§æãèãã¦ã¿ã¾ããã
ï¼Viewã¨Controllerã®ã¤ãªããã¯çç¥ï¼
Â
Â
ã»ã³ã³ããã¼ã©ã¼ã«ã¯ããªãã¹ããã¸ãã¯ãæ¸ããªãã
ã»ã¢ãã«ã¯ã
ã(1)ãServiceã
ã(2)ãRepositoryã
ã(3)ãO/R Mapperãï¼DAOï¼
ãã®3層ã«åå²ãããï¼å称ã¯ä½ã§ãè¯ãï½ï¼
ã»Serviceã¯ãã³ã³ããã¼ã©ã¼ã«å¯¾å¿ããæ©è½ãåãæã¤ã
ãServiceã®ãã¡ã¤ã«æ°ãã¯ã©ã¹æ°ã¯å°ãªãã¦OKã
ãServiceã®ã¡ã½ããã¯å¤æ©è½ã§OKï¼ãã¤ã層ï¼
ãServiceã«ç½®ãããæ©è½ã¯ãåå©ç¨ããªãåæãªã®ã§ãæ±ç¨æ§ã¯ä½ãã¦OK
ã»Repositoryã¯ã1ã¡ã½ããï¼1æ©è½ã®ããã«ãåæ©è½ã§ã·ã³ãã«ã«ããã
ãRepositoryã¯ãæ±ç¨æ§ãé«ããã¦ããããããªServiceããå©ç¨ã§ããããã«ããã
ãRepositoryã¯ããã«ãã¼é¢æ°ã®ããã«ãäºãã«å©ç¨ã§ããããã«ãã¦ãOKï¼âããã¯ããã¦ãããæ¹ãè¯ãã®ããï¼
ã»O/R Mapperï¼ORMï¼ï¼DAOï¼Data Access Objectï¼ã¯ãDBãã«ãã»ã«åããã
ãDAOããã¯DBãè¦ãããã©ãDAOããä¸ã®å±¤ã«ã¯DBãé è½åããã¦ããã
ãDAOã¯ã1ãã¼ãã«1ã¯ã©ã¹ã1ãã¥ã¼1ã¯ã©ã¹ã§ã1対1ã®å¯¾å¿ã«ããã
ãDAOã«ã¯ãçã®SQLãæ¸ãã¦ãOKã
ãDAOã¯ãscaffoldingã§èªåçæããã¦ããããããããã¯ãåºæ¬çãªCRUDã¡ã½ãããå®è£ ãã親ã¯ã©ã¹ãç¶æ¿ããã ãã§OKã«ãã¦ããã
ã»ãã¼ã¿ãã¼ã¹ï¼MySQLï¼ã§ã¯ããã¥ã¼ãæ´»ç¨ããã
ãDAOã§è¤æ°ã®ãã¼ãã«ãã¾ããå¦çãããå ´åã¯ãäºããã¼ãã«å士ãJOINãããã¥ã¼ãç¨æãã¦ããã1åã®ãã¥ã¼ã«å¯¾ãã¦DAOã®1ã¯ã©ã¹ãå²ãå½ã¦ãã°OKãÂ
Â
ãããªãããã§ãMVCã®ã¢ãã«ã®åå²ã試ãã¦ã¿ããã¨æãã¾ãã
ãã¾ãè¤éãªåå²æ¹æ³ã«ããã¨ãé¢åããããªããããªã®ã§ãRepositoryãçç¥ãã2層åå²ã§ãè¯ãããªï¼
Â
âä½ãè¯ãæ¹æ³ããã£ããæãã¦ãã ãããm(__)m
Â
Â
Â
- ä½è : Dustin Boswell,Trevor Foucher,é è¤åå¹³,è§å¾å ¸
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã¸ã£ãã³
- çºå£²æ¥: 2012/06/23
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- ãã®ååãå«ãããã°ãè¦ã
Â
ã追è¨ã2016/08/11
CodeIgniterã«é¢ãã¦ãããã¸ãã¹ãã¸ãã¯ï¼ãã¼ã¿ã®å¦çï¼ãç½®ãå ´æã¯ãã¢ãã«ä»¥å¤ã§ãOKãã¨ããåèæ å ±ãããã¾ããã
Â
ï¼åèï¼
MVCã§ãã£ã¨ãéè¦ãªãã¼ãã¯ã¢ãã«ã§ãããããããã¸ãã¹ãã¸ãã¯ããã¡ã¤ã³ã¢ãã«ã¨è¨ãããã³ã¼ãã¯ã¢ãã«ã«è¨è¿°ãã¾ãã
CodeIgniterã§ã¯ãMVC以å¤ã«ãã©ã¤ãã©ãªãã¨ããã«ãã¼ããåå¨ãã¾ããããã§ããã«ãã¼ã¯é¢æ°ãå®ç¾©ãããã®ã§ããã¯ã©ã¹ãå®ç¾©ããã«ã¯ãã©ã¤ãã©ãªã使ãã¾ãã
ã¤ã¾ããCodeIgniterã§ã¯ãã¸ãã¹ãã¸ãã¯ããã¡ã¤ã³ã¢ãã«ã
ã»application/modelsãã©ã«ãã«é ç½®ãã
ã»application/librariesãã©ã«ãã«é ç½®ãã
ã¨ããæ¹æ³ãèãããã¾ãã
ãã¼ã¿ã®å¦çã®å 容ã«ãã£ã¦ã¯ãã¢ãã«ã«ç½®ããªãã¦ããã©ã¤ãã©ãªã¼ããã«ãã¼ã«ç½®ãã¦ããã¦ã使ããã¨ãã§ãã¾ããï¼
Â
ï¼åèï¼
GoFã®ãã¶ã¤ã³ãã¿ã¼ã³ã§ãFacadeãã¿ã¼ã³ã¨ããä»çµã¿ã使ãã¨ãå¦çãåæ£ãã¦é ç½®ã§ãããã§ãã
Â
ãªãã»ã©ï¼ãããªãµãã«ãã¦è¥å¤§åããå¦çãåæ£ï¼ã¹ãªã åãã¦ããããã§ããâª
âæ å ±æä¾ã©ãããããã¨ããããã¾ããm(__)m