MVCã¯ãæŽç·Žããããé©ãã»ã©ãšã¬ã¬ã³ããªã¢ãŒããã¯ãã£ãœãªã¥ãŒã·ã§ã³ã§ãã ãã®ãã¿ãŒã³ããªããã°ãææ°ã®ã¢ããªã±ãŒã·ã§ã³ãã©ããªããæ³åã§ããŸããã
ã€ã³ã¿ãŒãããäžã§ã¯ããã¹ãŠã®æ å ±ãããã€ãã®æçã«æ£ãã°ã£ãŠããŸãããä»ã§ã¯ã1幎åã®ç¥ãåããšçµããã®ãªãç 究ã®åŸãã€ãã«èšãããšãã§ããŸããã¯ããç§ã¯ãã®ãã¿ãŒã³ãåºãç¥ã£ãŠããŸãã
äžè¶³ããŠãããã¹ãŠã®æ å ±ã1ãæã§åéããããšã«ããŸããã ãããèšäºãæžãçç±ã§ããã
tl; drïŒçµæãèªã¿åããŸãã æ®ãã¯å¿«é©ã«ãªããããé¡ãããŸãã
Gang of Fourã«ãããšãMVCã¯æŠç¥+ãªã³ã«ãŒ+ãªãã¶ãŒããŒã«éããŸããã ã³ã³ãããŒã©ãŒãšãã¥ãŒã¯ããªãã¶ãŒããŒãšããŠã¢ãã«ã«ç»é²ãããŸãã ãã¥ãŒã¯ãããèªäœã§ã³ã³ãããŒã©ãŒãæŠç¥ã®ãªããžã§ã¯ããšããŠç»é²ããæ§æã«ãã£ãŠãã®åäœãå®çŸããŸãã ã¢ãã«ã¯ãç¶æ ãå€åãããšãã«ãªãã¶ãŒããŒã«èŠåãåºããŸãã ãã¥ãŒã¯ããèªäœã«ä»ã®ãã¥ãŒãåã蟌ã¿ãŸããéåžžããã¥ãŒã¯ã¢ãã«ã«äŸåããä»ã®ã³ã³ãããŒã©ãŒãä»ããŠãŠãŒã¶ãŒã«ç°ãªãåäœãæäŸããŸãã ããã¯HMVCã§ã¯ãããŸããã ããã¯ãã®ãžã£ã³ã«ã®å€å žã§ãã
Webéçºã§ã¯ãMVCãæãäžè¬çãªãã¿ãŒã³ã§ãã ä»æ¥ãMVCãã¬ãŒã ã¯ãŒã¯ã®æŠå¿µã¯ããäžè¬çãªãã®ã§ãããã³ãŒãã3ã€ä»¥äžã®ã³ã³ããŒãã³ãã«æ£ããåå²ããããã«ããããã®ãã¬ãŒã ã¯ãŒã¯ã«ã€ããŠç§ãã¡ã®åšãã®äººã ãååã«ç¥ã£ãŠãããšä¿¡ããŠããŸãã æ®å¿µãªãããMVCãã¬ãŒã ã¯ãŒã¯ã®æ®åãšããŠãŒã¶ãŒã«éçºãã¢ããªã±ãŒã·ã§ã³éçºãããã³ãµããŒãã®å®¹æããæäŸããããšããè©Šã¿ã«ãããåºç€ãšãªããã¿ãŒã³ã®åºæ¬ã¯å€±ãããŠããŸãã
ãããããMVCã¯ãã¢ãã«ã®ç¶æ ã®å€æŽäžã«äžå®ã®ã©ã³ã¿ã€ã ãäžè¶³ããŠãããããã¯ã©ã€ã¢ã³ããµãŒããŒã¢ããªã±ãŒã·ã§ã³ã«ã¯å®è£ ã§ããŸããã ç§ã¯ç¹ã«ãªãã¶ãŒããŒã«ã€ããŠè©±ããŠããŸãã ã¢ãã«ãå€æŽããåŸããã¥ãŒãæŽæ°ããŠãæå³ããããŸãããããã¯ãã¯ã©ã€ã¢ã³ãäžã§ãã¥ãŒãååŸããã¢ãã«ã¯ãµãŒããŒäžã«ããããã§ãã ãã€ãŠãJava Webã¢ããªã±ãŒã·ã§ã³ã®ãã®åé¡ã解決ããããã«ãå€ãè¯ãMVCã«åºã¥ããŠã¢ãã«2ãã¿ãŒã³ãéçºãããŸããã
ãã®ãã¿ãŒã³ã®æ¬è³ªã¯ãMVCãhttpãããã³ã«ãšã€ã³ã¿ãŒãããã®çŸå®ã«åãããŠåŸ®èª¿æŽããããšã§ãã ãã®ãã¿ãŒã³ã¯ãã³ã³ãããŒã©ãŒããŠãŒã¶ãŒããã®ãªã¯ãšã¹ããåãåããªããžã§ã¯ããšèŠãªããŸããã ã³ã³ãããŒã©ã¯ããªã¯ãšã¹ãã«åºã¥ããŠãªã¯ãšã¹ãã解æããç¹å®ã®ã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åããã¢ãã«ããã®ä»ã®ããŒã¿ããã¥ãŒã«è»¢éããããšã«ããç¹å®ã®ãã¥ãŒãå°åºããå¿ èŠããããŸãã ãã¥ãŒèªäœã¯éåžžã®JSPã§ãã ãã®ã¢ãã«ã¯ãããŒã¿ããŒã¹ãšéä¿¡ãããªããžã§ã¯ãïŒORMïŒã®ããŒãã«è¡ã衚瀺ããããã«äœ¿çšãããŸããã ããªãã¿ã®ããã§ããã ãŸãããªãã¶ãŒããŒãšãªã³ã«ãŒã¯ãããŸããã
ããèŠããšãããã2ã€ã®ãã¿ãŒã³ã®éãã¯éåžžã«å€§ããã§ãã ã³ã³ãããŒã©ãŒãããã¥ãŒãžã®ããŒã¿ã®è»¢éã¯ããã§ã«MVCãã¿ãŒã³ã®é倧ãªéåã§ãã åŸæ¥ã®å®è£ ã§ã¯ããã¥ãŒèªäœã¯ã¢ãã«ããçŽæ¥ãŸãã¯ã³ã³ãããŒã©ãŒãä»ããŠããŒã¿ãååŸããŸããããå€ãã®å Žåãã³ã³ãããŒã©ãŒã¯ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããŠã¢ãã«äžã®ãŠãŒã¶ãŒã¢ã¯ã·ã§ã³ãåŠçããããã«äœ¿çšãããŸããã ã€ãŸããã³ã³ãããŒã©ãŒã¯ããã¥ãŒã®åäœã§ãã 奎é·ã ãã¹ã¿ãŒã§ã¯ãããŸããã
æ®å¿µãªããããã®ã¢ãããŒãã¯httpãããã³ã«ã«ã¯é©ããŠããŸããã ãµãŒããŒãžã®æ¥ç¶ãåæãããã¢ããªã±ãŒã·ã§ã³ãåäœãåæ¢ããŸããPHPã®å Žåã次ã®ãªã¯ãšã¹ãã®åã«å®å šã«åæ¢ããŸãã
ã¢ãã«2ã¯ãMVCãšåæ§ã3ã€ã®ãã¿ãŒã³ãã¹ãŠã«åºæã®ãã®ã§ããããããã®å®è£ ã®ã¿ãã4人ã®ã®ã£ã³ã°ãã«ãã£ãŠèšè¿°ãããåŸæ¥ã®ãªããžã§ã¯ãå®è£ ãšã¯å€å°ç°ãªããŸãã
ãªã³ã«ãŒã¯æ®ããŸããããJSPãPHPãERBãªã©ãè€éãªãã³ãã¬ãŒããã¡ã€ã«ãäœæããããšã§å®è£ ãããŠããŸãã ãããããããæäœããæ¹æ³ã¯ã»ãšãã©ãããŸããã çŸåšã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ã Vãéšåå šäœã®é¢ä¿ãšããŠäœ¿çšã§ãããšã¯èããããŸããã
æŠç¥ãæ¶ããŸããã§ãããã誰ããå¿ããŠããŸããã³ã³ãããŒã©ãŒã«æ°ãã圹å²ãã€ãŸãèŠæ±ãã³ãã©ãŒãäžããŸããã çŸåšã®ã»ãšãã©ã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãã³ã³ãããŒã©ãŒã¯äœããã©ãã§ãã©ã®ããã«è¡ããã決å®ããç¥ã§ãã ã³ã³ãããŒã©ãŒã¯ã¢ãã«ãåŒã³åºããã³ã³ãããŒã©ãŒã¯ã¢ãã«ãä¿åããã³ã³ãããŒã©ãŒã¯ã¢ãã«ã«æžã蟌ã¿ãã³ã³ãããŒã©ãŒã¯ãã¥ãŒãçæããã³ã³ãããŒã©ãŒã¯...ããããŸãã ã³ã³ãããŒã©ãŒããã¹ãŠãè¡ããŸãã éåžžã®åäœãããã³ã³ãããŒã©ãŒã¯GodObjectã«å€ãããŸããã
ãªãã¶ãŒããŒã ãããæãé£ããéšåã§ãã 誰ãããªãã¶ãŒããŒã®ä»çµã¿ãç¥ã£ãŠããŸãã 誰ãããåäžã®httpãªã¯ãšã¹ãã®ã³ã³ããã¹ãã§åŸæ¥ã®ãªãã¶ãŒããŒãå®è£ ããããšãã©ãã»ã©é£ããããæã«ã¯æãã§ããããšãç¥ã£ãŠããŸãã ãã®ãã¿ãŒã³ã¯ãç»é¢äžã®ããŒã¿ãæŽæ°ããããã«èšèšãããŠãããWebãœã±ãããé·ãããŒãªã³ã°ãããã³ãã®ä»ã®éæ³ããªããã°ããããå®è£ ããã®ã¯éåžžã«å°é£ã§ãã ã¢ãã«2ã§ã¯ããªãã¶ãŒããŒã¯ã³ã³ãããŒã©ãŒãšãã¥ãŒã®äž¡æ¹ã§ãããåžžã«ã§ã¯ãªããhttpèŠæ±ã®åŸã«ç¶æ å€æŽã®èªã¿åããè¡ãããŸãã
ãšãŠãé¢åã§ãã ãã ããMVCãšã¢ãã«2ã«ã€ããŠãã®ããã«è©±ããšãå€ãã®ããšèªäœãæãç«ã¡ãŸãã
次ã«ãåã³ã³ããŒãã³ãã®è²¬ä»»ã«ã€ããŠèª¬æããŸãã ç§ã¯ç¹å®ã®èšèªã«éå®ãããŠããªãã®ã§ãæ¬æã«ã¯ãã¯ã©ã¹/æ§é ãã¿ã€ãã®çµã¿åãããååšããå¯èœæ§ããããŸãããããã¯çŸåšã®ç°ãªãèšèªã«é¢é£ããŠããŸãã ç§ã¯ãã®èšäºãrubyïŒrailslïŒ/ phpéçºè ã ãã§ãªãæçšã§ããããšãæãã§ããŸãã æžããããã®ã¯ãã¹ãŠããã®æ§é ãpythonãCïŒãJavaããããŠãã¡ããJavaScriptãåããGolangã«ãé¢é£ããŠããŸãã
ãã®èšäºã¯ããã€ãã®ã¢ãããŒãã§æžãããŠããŸããéè€ããæ å ±ãå€æããªãã§ãã ããã
ã¢ãã«
ã¢ãã«ã«ã€ããŠæ°ããããšã¯äœã§ããïŒ ããšãã°ã ãã®çŽ æŽãããèšäºã§ã¯ãã¢ãã«ã®æ¬è³ªãå®å šã«æããã«ãããŠããŸãã ã¢ãã«ã¯ç¶æ ã§ãããããžãã¹ããžãã¯ã§ãããããŒãã«/ mongoããã¥ã¡ã³ã/ãã¡ã€ã«ãžã®åäžã®ãšã³ããªãã€ã³ãã§ãã ãŠãŒã¶ãŒã®ãªã¯ãšã¹ãéã§ç¶æ ãä¿åããå¿ èŠãããå Žåãã¢ãã«ããããæ åœããŸãã ãªããžã§ã¯ãã®ã³ã³ããã¹ãã§èª¬æããå Žåããã£ãŒã«ããå¿ èŠãªã®ã¯ã¢ãã«ã§ãã ã¢ãã«ãã¹ããŒãã¬ã¹ã«ããããšã¯ã§ããŸããã ã¢ãã«ã¯ãããŒã¿ã®æ€èšŒãšé¢é£æ§ãæ åœããŸãã
ãã¡ãããUIãªãã§ã¢ããªã±ãŒã·ã§ã³ãèšè¿°ã§ãããšã³ãã£ãã£ãããå Žåããããã¯ã¢ãã«ã§ãã
ãã¥ãŒãšã³ã³ãããŒã©ãŒ
ã¯ã©ã·ãã¯MVCã§ã¯ããã¥ãŒã¯ç»é¢ã«æ å ±ã衚瀺ããåå¥ã®ãªããžã§ã¯ãã§ãã CLIã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠèª¬æããå Žåãããã¯ããçš®ã®stdout.printlnïŒïŒã§ãã Webã¢ããªã±ãŒã·ã§ã³ã¯ãã¯ã©ã·ãã¯MVCã®ä»£ããã«ã¢ãã«2ã䜿çšããŸããããã¯ããã¥ãŒãããŒã¯ã¢ãããšçµã¿èŸŒã¿ãã³ãã¬ãŒãã³ãŒããæã€åãªããã¡ã€ã«ã§ããããšãæå³ããŸãã äžèŠãããšãåçŽãªãã³ãã¬ãŒãã¯ã·ã¹ãã å ã§ããã»ã©éèŠã§ã¯ãªãããã§ãã å®éããŠãŒã¶ãŒã䜿çšã§ããã¢ã¯ã·ã§ã³ã決å®ããã®ã¯ãã¥ãŒã§ãã
ãã¥ãŒã¯ãæŠç¥ãšã¬ã€ã¢ãŠãã®2ã€ã®ãã¿ãŒã³ã®äžéšã§ãã ãã¥ãŒã®åäœã¯ã³ã³ãããŒã©ãŒã«å®è£ ãããŠããŸãã ã³ã³ãããŒã©ãŒã¯ç¹å®ã®ã¢ã€ãã¢ã®äžéšã«ãããªãããšãããããŸãã ãŸããç¹å®ã®ãã¥ãŒã«å¯ŸããŠç°ãªãåäœãå¿ èŠãªå Žåã¯ãå¥ã®ã³ã³ãããŒã©ãŒã«çœ®ãæããããšãã§ããŸãã
å®éããé åçãªæ è¡è ãã®æãããæããå€ãã®éæ³ããããŸãã
貪欲ãªã³ã³ãããŒã©ãŒ
ã倪ãã¢ãã«ã现ãã³ã³ãããŒã©ãŒãã®æŠå¿µã«ãããã³ã³ãããŒã©ãŒã®ã¢ã¯ã·ã§ã³ã1è¡ã«åçŽåããåŸåã«æ°ä»ããŸãã-ã¬ã³ããªã³ã°ïŒããã¥ãŒãïŒãè¿ããŸãã ãã®çµæãã»ãšãã©ã®ã¢ã¯ã·ã§ã³ãšããŒã¿ãµã³ããªã³ã°ã¯ãã¥ãŒã§çŽæ¥å®è¡ãããŸãã ãã®ã¢ãããŒãã¯ããã¥ãŒã«è»¢éãããããŒã¿ãå°ãªãã»ã©ããã¥ãŒãšã³ã³ãããŒã©ãŒãäºãã«ç¬ç«ããããã«ãªããšããç¹ã§è°è«ãããŠããŸãã åçŽåã¯ããã³ãã¬ãŒããã¡ã€ã«ã§ã¢ãã«ãçŽæ¥æäœãå§ãããšãäžåçã«ãªããŸãã 誰ããã³ã³ãããŒã©ãŒã§ã³ãŒããæžãããšããšãŠãæããŠããçç±ãããããŸããã 1ããŒã¹ã®ããŒã¿ããã¥ãŒã«æž¡ããŠããããã¯ç§ã®ãã¥ãŒãããããã¹ãŠã䜿çšããå¿ èŠããããšããæå³ã§ã¯ãããŸããã äœããéããŠç®±ã«å ¥ããç¹å®ã®äººã«éµéãããšæ³åããŠãã ããã ãããã®ããšã¯ããå¿ èŠãããŸãããåä¿¡è ãããããã©ããããã¯çµ¶å¯Ÿã«éèŠã§ã¯ãããŸããã 圌ã¯ã«ããã«ãŸãã¯2ã€ãéžæããæ®ããæããããšãã§ããã ç§ã¯èªåèªèº«ã®ããã«ã貪欲ã§æ zyãªã³ã³ãããŒã©ãŒããšããèšèãäœãåºããŸããã
ãã®èšäºã§ã¯ããã¬ãŒã ã¯ãŒã¯çšèªã®ã³ã³ãããŒã©ãŒã¢ã¯ã·ã§ã³ã¯MVCçšèªã®ã³ã³ãããŒã©ãŒã§ãããšè¿°ã¹ãŠããŸãã èšäºèªäœãçŽ æŽããããšããäºå®ã«ãããããããç§ã¯ãã®å£°æã«åŒ·ãå察ããŸãã ã¢ã¯ã·ã§ã³ã¯ããã¥ãŒã«å¯ŸãããŠãŒã¶ãŒã®ã¢ã¯ã·ã§ã³ã§ãã ããã¯è¡åã®éèŠãªéšåã§ãã ã¢ã¯ã·ã§ã³ãæžãæãããšãåäœã¯å€ãããŸãããå®æããã¯ã©ã¹ã®ã³ãŒãã«äŸµå ¥ãããããã¯ã©ã¹ã³ãŒããäœãå€æŽããªãã§ãã ããã ã³ã³ãããŒã©ãŒã亀æãããšããã¥ãŒã®åäœãå€æŽãããŸãããæŠç¥ã®æ¢åã®ãªããžã§ã¯ãã¯å€æŽãããŸããã ããšãã°ãAngular.jsãåãäžããŸãã ã³ã³ãããŒã©ãŒã®éå§äœçœ®ãšã¡ãœããã®äœçœ®ãæ確ã«ãã¬ãŒã¹ããŸãã ã³ã³ãããŒã©ãŒã¡ãœããã¯ãng-clickãng-submitãªã©ã®ãã£ã¬ã¯ãã£ãã䜿çšããŠãäœããã®æ¹æ³ã§ãã¬ãŒã³ããŒã·ã§ã³ãšå¯Ÿè©±ããŸãã çµè«ãšããŠãã³ã³ãããŒã©ãŒã¯æ¬æ Œçãªã¯ã©ã¹ã§ããããã®ã¡ãœããïŒã¢ã¯ã·ã§ã³ïŒã¯ããŠãŒã¶ãŒãã¢ããªã±ãŒã·ã§ã³ãšå¯Ÿè©±ãããã¥ãŒã®ã¢ã¯ã·ã§ã³ã§ãã ng-controllerãã£ã¬ã¯ãã£ãã§ã³ã³ãããŒã©ãŒã眮ãæããå Žåããã¥ãŒã®åäœã¯ç¹å®ã®ã³ã³ãããŒã©ãŒã®ã¡ãœããïŒã¢ã¯ã·ã§ã³ïŒã®å®è£ ã«å¿ããŠå€ãããŸãã
æ¬åœã«æãã®ã¯ãã³ã³ãããŒã©ãŒãã¢ããªã±ãŒã·ã§ã³ã®äžã§æãåå©çšãããéšåã ãšããããšã§ãã ãªã«ïŒ ç§ã«ãšã£ãŠãã³ã³ãããŒã©ãŒã¯äŸå€çã«1åéãã®ã³ãŒãã§ãã ã¢ã¯ã·ã§ã³ïŒã¢ã¯ã·ã§ã³ïŒã¯åå©çšã§ããŸããç§ã¯åæããŸãã ç¹ã«CRUDã¢ã¯ã·ã§ã³ã§ã¯ããã®ã¢ã¯ã·ã§ã³ãé¢é£ä»ããã¢ãã«ã®ã¯ã©ã¹/æ§é ãç°¡åã«æå®ã§ããŸãã ã³ã³ãããŒã©ã§ã®ã³ãŒãã®è€è£œã¯éåžžã®æ¹æ³ã§ãããªããªãããããã¯åŸ®åŠã§ããããã¹ãŠã®ããžãã¯ãé ç·ãããŠããã¢ãã«ã®ã¡ãœãããåŒãèµ·ããã ãã ããã§ãã ç°ãªãã³ã³ãããŒã©ãŒã«å¯ŸããŠåãïŒãŸãã¯ã»ãŒåãïŒã¢ã¯ã·ã§ã³ã2åç¶ããŠèšè¿°ããå¿ èŠãããå Žåã¯ãããããããšãªããããè¡ããŸãã ç°ãªãã³ã³ãããŒã©ãŒã§åãã¢ãã«ã¡ãœãããåŒã³åºãå¿ èŠãããå Žåã¯ããããè¡ããŸãã ã³ã³ãããŒã©ãŒã¯ãååãšããŠãè¡šçŸãšããŠç Žæ£ããŠåäœæã§ããŸãã
ã¢ãã«ã¯æšãŠãã®ãé£ãããå¿ èŠãããŸããã ååãšããŠãã¢ãã«ã€ã³ã¿ãŒãã§ã€ã¹ã¯ãã¢ããªã±ãŒã·ã§ã³ã®éçºäžãŸãã¯ã¢ããªã±ãŒã·ã§ã³ããã¢ããªã±ãŒã·ã§ã³ãžã®ã¢ãã«ã®è»¢éäžã«å€æŽãããŸããããè£è¶³ã®ã¿ã§ãã ã»ãšãã©ãã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ã®ã³ã³ãããŒã©ãŒãšãã¥ãŒã¯ç¬èªã®ãã®ã§ãã ãããã¬ãŒã ã¯ãŒã¯ããå¥ã®ãã¬ãŒã ã¯ãŒã¯ã«ã³ã³ãããŒã©ãŒã移åããŠã¿ãŠãã ãããããããã°ãç§ã話ããŠããããšãç解ã§ããŸãã ãŸããã¢ãã«ãWebã¢ããªã±ãŒã·ã§ã³ããã¢ãã€ã«ãŸãã¯ãã¹ã¯ãããã«è»¢éããããšãã§ããŸãããã³ãŒããå€æŽããããšãªãïŒãŸãã¯ã»ãšãã©ãªãã§ïŒã奜ã¿ã®ãã¹ããéæ¯ãè¡ãããšãã§ããŸãã
ã³ã³ãããŒã©ãŒã¯ãç°¡åãªãªãã¡ã¯ã¿ãªã³ã°ã«åœ¹ç«ã€ã¯ãã§ãã ãããããåäžã®ã¢ã¯ã·ã§ã³ãå¥ã ã®ãªããžã§ã¯ãã«åé€ããããšã¯ãã³ã³ãããŒã©ãŒã®åå©çšã«ãããŸããããå€ãã®æ³šæãæãã»ã©éèŠã§ã¯ãããŸããã 確ãã«ãããããå Žåã«50ã®ã¢ã¯ã·ã§ã³ã¯ã©ã¹ã§ã¯ãããŸããã
æ¯ãèããšããŠã®ã³ã³ãããŒã©ãŒ
ãæ°ã«å ¥ãã®mp3ãã¬ãŒã€ãŒïŒã¹ããŒããã©ã³ã®ã¢ããªã±ãŒã·ã§ã³ãæå³ããŸãïŒãèŠãŠã¿ãŸãããã ããã§ã®ãã¬ãŒã³ããŒã·ã§ã³ã¯ãé£æ¥ããæ²ã«åãæ¿ãããã¿ã³ãåæ¢ãåçããã¬ã€ãªã¹ãã§ãã åæ¢ãã¿ã³ãšæ倱ãã¿ã³ã§ã¯ããã¹ãŠãæ確ã§ãããã³ã³ãããŒã©ãŒã®å€æŽã«å¿ããŠãããã®åäœãå€ãããšã¯æããŸããããæ²ã«åãæ¿ããããã®ãã¿ã³ã¯çŸåšã®æ²ã®æ©éã/å·»ãæ»ãçšã®ãã¿ã³ã«ããããšãã§ããŸãã å šäœãšããŠãåãèããæã£ãŠãã³ã³ãããŒã©ãŒã亀æããã ãã§ãã®åäœãå€æŽã§ããŸãã
æºåž¯é»è©±ã®é³æ¥œåçäžã®ããã¯ç»é¢ã§ã¯ãå·»ãæ»ããã¿ã³ã䟿å©ãªããã«æ§æãå€æŽããã¢ããªã±ãŒã·ã§ã³èªäœã§ã¯æ²ãååŸã«å·»ãæ»ãããšãæ³åã§ããŸãã ãŸããã€ãã³ããä»ããŠã©ã³ã¿ã€ã ã§ã³ã³ãããŒã©ãŒãå€æŽã§ããŸãã å·»ãæ»ããã¿ã³ã«æã眮ãã€ãã³ãã¯ãçŸåšã®æ²ã®å·»ãæ»ãã§ã³ã³ãããŒã©ãŒãèµ·åããŸããã¯ã€ãã¯ã¿ãã-ã³ã³ãããŒã©ãŒãèµ·åããŠãããŸããŸãªæ²ã«åãæ¿ããŸãã ã«ãŒã¿ãŒãæãåºãããŸãããïŒ äž¡æ¹ã®ã³ã³ãããŒã©ãŒã§ãplayã¢ã¯ã·ã§ã³ãšstopã¢ã¯ã·ã§ã³ã®å®è£ ãéè€ããŠããŸãããããã¯ãã¿ãŒã³æŠç¥ã«ãšã£ãŠã¯ååã«åãå ¥ããããŸãã ãããŠãäž¡æ¹ã®ã³ã³ãããŒã©ãŒã¯åãè¡šçŸã䜿çšããŸãã
MVCã§ã¯ããã¥ãŒã®ã³ã³ãããŒã©ãŒã ãã§ãªããåäžã®ã³ã³ãããŒã©ãŒã®ãã¥ãŒã眮ãæããããšãã§ããŸãã è¯ãäŸã¯ããæ°ã«å ¥ãã®ãã¡ã€ã«ãããŒãžã£ãŒã«ãã¡ã€ã«ã衚瀺ããããšã§ãïŒã¿ã€ã«ããªã¹ããããŒãã«ãªã©ã ãªã³ã©ã€ã³ã¹ãã¢ã®åºé ã®ããã§ããã ãŸãããã¡ã€ã«ãããŒãžã£ãŒãããŒã¿ãããã€ããŒããã¥ãŒãããã³åäœïŒã³ã³ãããŒã©ãŒïŒãšããŠæ³åããŠãã ããã ãããŠãMVCãçŸå®äžçã§ç§ãã¡ã®åšãã«ã©ã®ããã«é©çšãããããèŠãã§ãããã
åãååã¯ãåäžã®ã€ã³ã¿ãŒãã§ãŒã¹ãåããã¡ãã£ã¢ã»ã³ã¿ãŒã§ãæ©èœããŸãããããŒã¿ã®ã³ã¬ã¯ã·ã§ã³ïŒåçãé³æ¥œããããªïŒã¯ç°ãªããŸãã åã³ã¬ã¯ã·ã§ã³ã¯ããã¥ãŒãšåäœã®äž¡æ¹ãå€æŽã§ããŸããããã«ãåããã¥ãŒã«å¯ŸããŠè€æ°ã®åäœïŒã³ã³ãããŒã©ãŒïŒãæ··åšãããããšãã§ããŸãã ããšãã°ããããªã®å Žåãããã€ãã¢ã¯ç»åïŒã¢ã¯ã·ã§ã³ã®è¡šç€ºïŒãšé³æ¥œïŒåæ¢ãåçãå·»ãæ»ãïŒã®äž¡æ¹ã«é©ããŠããŸãã
ãŠã£ãžã§ãã
ãŠã£ãžã§ããã¯ã Vãæå³ãããã¹ãŠã®ãã®ã§ãã
å€ãã®å ŽåããŠã£ãžã§ããã¯ã·ã¹ãã ã®ç¬ç«ããã³ã³ããŒãã³ããšããŠæ±ãããŸãã åæ§ã«ããã©ã°ã€ã³ãã¥ãŒãæã€ãªããžã§ã¯ãã¯ã ã»ãšãã©ã³ã³ãããŒã©ãŒã®ãããªãã®ã§ããã€ãŸããã³ã³ãããŒã©ãŒã®ãããªè²¬ä»»ãæã£ãŠããŸãã ã¯ãããããã å€ãã®å Žåã圌ãã¯ã»ãšãã©æåéããããåã蟌ãã§ãã¢ãã«ã«é¢ãããã¹ãŠã®äœæ¥ã貧匱ãªãŠã£ãžã§ããã«æŒã蟌ã¿ãŸããã€ãŸãããªã¯ãšã¹ãã®ãã£ã«ã¿ãªã³ã°ãé€ããªãŒã¬ãã€ã¶ãŒã®ãã¹ãŠã®äœæ¥ã§ãã ã»ãŒã³ã³ãããŒã©ãŒã§ãããïŒ
ãŠã£ãžã§ãã-ç¥
Yiiã®äŸ¿å©ãªãŠãŒã¶ãŒã¢ãžã¥ãŒã«ãæ¢ããŠGitHubã調ã¹ããšãã«ããŠã£ãžã§ããã®è²¬ä»»ãšç¥èã®åé¡ã«ã€ããŠèããŸããã ãã以åã¯ããŠã£ãžã§ããã¯ã«ã¹ã¿ã ãã³ãã¬ãŒãã§ãããããããããŠã³ã¡ãã¥ãŒãPjaxã³ã³ãããŒããŸãã¯åãYiiã®GridViewãªã©ã®ãã©ã°ã€ã³JavaScriptã䜿çšããŠããå¯èœæ§ããããŸããã ããã«åºã¥ããŠãããŒã¿ãã¢ãã«/ã¢ãã«ã®ã³ã¬ã¯ã·ã§ã³ãšããŠååŸããå éšã«ãŒã«ïŒæ £ç¿ïŒããã³èšå®ïŒæ§æïŒã«åŸã£ãŠããŒã¿/ã¢ãã«ã衚瀺ããã¯ã©ã¹ãååŸããŸãã ãŸãã¯ãã¢ãã«ã§ã¯ãŸã£ããæ©èœããããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã«ãã¶ã€ã³/åäœãè¿œå ããã ãã§ãã
ãŠã£ãžã§ããã§ãã¢ãã«ã䜿çšããŠä»ã®æäœãçŽæ¥äœæãäœæãããã³å®è¡ããã®ãèŠããšããç§ã¯ã·ã§ãã¯ãåããŸããã äžæ¹ã§ã¯ãLoginFormãŠã£ãžã§ãããšLoginFormã¢ãã«ãããå Žåãã¯ã©ã¹ã䜿çšããŠãã¢ãã«ãæäœããããšã«ãããŠãŒã¶ãŒãæ€èšŒããã·ã¹ãã ã«ãã°ã€ã³ããããšãè«ççã«æããŸãã ããã¯ã»ãã®æ°è¡ã§ãã å¥ã®ãŠãããŒã¹ãŸãã¯å°ããªãããžã§ã¯ãã®ã©ããã«ãããããããŸããããäžèŠæš¡ã®ãããžã§ã¯ããŸãã¯ã¢ãžã¥ãŒã«å šäœã§ã¯ãè€æ°ã®ã³ãŒãã®è€è£œãšãæ§è³ªã®ç°ãªãã³ã³ããŒãã³ãã®è²¬ä»»ã®æ··åãçããŸãã
ãã®ãããªèšèšã®äžäŸã¯ããã¹ãŠã®ããžãã¯ãšè¡šçŸããŠã£ãžã§ããã«åã蟌ãŸããŠããBitrixã§ãããäœããã®æªç¥ã®çç±ã§ã³ã³ããŒãã³ããšåŒã°ããŸãã
ããŸããŸãªãã¬ãŒã ã¯ãŒã¯ã®ãããäžã®åæ§ã®äŸã®åŸãç§ã¯ãçªç¶ãããæ£ããæ¹æ³ã ããšèããŸããã ãããŠãç念ãç§ã®é ã«å¿ã³èŸŒãã ã ãã¹ãŠã®ããžãã¯ããŠã£ãžã§ããã«ããã·ã¥ãããšãã³ã³ãããŒã©ãŒã¯ç¹å®ã®ãã¥ãŒã®è¡šç€ºã®ã¿ãåŠçããŸãã ããããããã¯ãã¿ãŒã³ã®é倧ãªéåã§ãã ãŠã£ãžã§ãããVã®èŠçŽ ã§ããå Žåããã®äžã§ã¢ãã«ãæäœããããšã¯ãããŸããã ã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åããããšã§ãããã³ã³ãããŒã©ã§å®è¡ããããšããå§ãããŸããä¿åã¯ãã¡ããã§ãã
äžæ¹ãããããã€ã³ãšãã®äœæ¥ã®æŠå¿µã¯ããŠã£ãžã§ããã®å¿ é ã®æ§æã«ã¯é©åããŸããã ããã«ãç§ã¯èšå®ãããèŠçŽãæ¬åœã«å¥œãã§ããããã¯ããããŸã§ã®ãšãããRailsã§ãç®±ããåºããŠããã«ãè¡šçŸããã®ãæåã ãšæããŸãã ãã®çµæãç§ã¯æ¬¡ã®çµè«ãåºããŸããïŒã€ã³ã¹ã¿ã³ã¹ããŠã£ãžã§ããã«è»¢éãããããŠã£ãžã§ãããç¹å®ã®ã¢ãã«ãšåãååã§ããå Žåã«ã®ã¿ãã¢ãã«ããŠã£ãžã§ããã§ã€ã³ã¹ã¿ã³ã¹åã§ããŸãã ã ãããããŠã£ãžã§ããã¯æ±ºããŠã¢ãã«ã«æžã蟌ãã ããã¢ãã«ãä¿åãããããããšã¯ã§ããŸãããããã¯ã³ã³ãããŒã©ãŒã®ã¿ã¹ã¯ã§ãã
ãŠãŒã¶ãŒå ¥åã®åŠçã«é¢ããŠã¯ãäžèšã®ãã¹ãŠãéåžžã«è«ççã«æããŸãã LoginFormã«ããŒã¿ãå ¥åããåŸããŠãŒã¶ãŒãæ¿èªããŠããŒãžã«ãšã©ãŸãå¿ èŠãããå ŽåããŠã£ãžã§ããã§çŽæ¥åŠçããã«ãããè¡ãã«ã¯ã©ãããã°ããã§ããïŒ æããã«ãããã«ã¯å¥åã®ã³ã³ãããŒã©ãŒãå¿ èŠã§ãããã³ã³ãããŒã©ãŒã¯æ瀺çãªãªãã€ã¬ã¯ããæå®ããªãå ŽåããŠãŒã¶ãŒãããŒãžãã移åãããŸãã ã€ã³ã¿ãŒãããã§ã¯ãã»ãšãã©ã®å Žåã次ã®3ã€ã®ã·ããªãªã䜿çšãããŸãã
- ãŠãŒã¶ãŒã¯ãã°ã€ã³ããŒãžã«ãªãã€ã¬ã¯ãããããšã©ãŒã衚瀺ãããïŒãã¹ã¯ãŒããæ£ãããªãïŒããå人ã¢ã«ãŠã³ãã®èªèšŒãšè¡šç€ºãè¡ãããŸãã
- ãŠãŒã¶ãŒã¯ãã°ã€ã³ããŒãžã«ãªãã€ã¬ã¯ãããããšã©ãŒã衚瀺ãããïŒäžæ£ãªãã¹ã¯ãŒãïŒãŸãã¯èªèšŒãè¡ãããäžéãã¥ãŒã®ããïŒãŸãã¯ãªãïŒå/ã¡ã€ã³ããŒãžã«ãªãã€ã¬ã¯ããããŸãïŒphpBBãªã©ã®ãã©ãŒã©ã ãæãåºããŠãã ããïŒã
- ãŠãŒã¶ãŒã¯AJAXãªã¯ãšã¹ããä»ããŠãã°ã€ã³ããããŒãžã«æ®ããŸãã æ¿èªã«äŸåãããã¹ãŠã®ãããã¯ïŒãã¹ã±ãããªã©ïŒã¯ãäœããã®çš®é¡ã®Pjax.reloadãä»ããŠããŸãã¯åã«ããŒãžããªããŒãããããšã«ãã£ãŠæŽæ°ãããŸãã
æåã®2ã€ã®ã±ãŒã¹ã§ã¯ããŠã£ãžã§ããã¯çŸåšã®ãã¬ãŒã³ããŒã·ã§ã³ãšåŠçã®ãã¡ãµãŒããšããŠã®ã¿äœ¿çšãããŸãã ãã®ãªãã·ã§ã³ã¯å Žæã§ãã æåŸã®äŸã§ã¯ããŠã£ãžã§ããã¯æé»çã«ã³ã³ãããŒã©ãŒã«æ¥ç¶ãããŠãããæ§æãä»ããŠçœ®ãæããããšãã§ããŸãã
ãã®å ŽåããŠã£ãžã§ããã¯æå°éã®ããžãã¯ã§ããã衚瀺ãããã³ãã¬ãŒãã§ãã ãŠãŒã¶ãŒãèªèšŒãããŠããªãå Žåããã©ãŒã ã衚瀺ããŸãã èš±å¯ãããŠããå Žåãæšæ¶ã衚瀺ããŸãã ãã³ãã¬ãŒãå ã«ä»ã®èŠçŽ ããªããã°ã Vã§æäœããå¿ èŠã¯ãããŸããã
3ã€ã®ã·ããªãªã¯ãã¹ãŠç°¡åã«å®è£ ã§ããã³ãŒãã®éè€ã¯é¿ããããŸããããŠã£ãžã§ããã§çŽæ¥ã¢ãã«ãæäœãããããè€éã§ããäž»ãªããšã¯ãééã£ãã¢ãããŒãã®åçŽãã«èªæãããªãããšã§ãã
ããã¯ãã¢ããªã±ãŒã·ã§ã³ã®åãããŒãžãã«åå¥ã®phpãã¡ã€ã«ã䜿çšããå€ä»£ã®æ¹æ³ãšå®è³ªçã«éãã¯ãããŸããã
ããã«ãŠã£ãžã§ãããå¿ èŠã§ãïŒ
æ¢è£œã®å°ããªãœãªã¥ãŒã·ã§ã³ãå€æ°ããããããã¬ãŒã ã¯ãŒã¯ã¯éçºè ãå£åãããŸãã äºåã«å®çŸ©ããããŠã£ãžã§ããã®äœ¿çšãéå§ãããããã®ãŠã£ãžã§ããã®åé¡ã解決ããŠã¢ããªã±ãŒã·ã§ã³ã®èšèšã«äœããã®åœ¢ã§é©åããããã«ããŠããããšã«æ°ä»ããŸãããã2ã3èšèªã§ã³ãŒãã®ããã€ãã®è¡ãæžãæ¹ãã¯ããã«ç°¡åã§ãã
éåžžã®AJAXãªã¯ãšã¹ãã§ååãªå Žåã§ããåè©äŸ¡ãããPJAXãã©ãã«ã§ã衚瀺ãããŸãã ãã¬ãŒã ã¯ãŒã¯ã«åãŸãããã«JavaScriptã³ã³ããŒãã³ããäœæãã人ã¯ã»ãšãã©ããŸããã GitHubã§ãéçºè ãPjaxãŸãã¯ããã«é¢é£ããä»ã®äœæ¥ããªããŒãããã®ã«å¿ èŠãªJavaScriptãè°è«ããæ¹æ³ãäœåºŠãèŠãŠããŸããããJSã«éªéãããªãããã«ãããå€ãã®èšå®ãæšæºãã¬ãŒã ã¯ãŒã¯ãŠã£ãžã§ããã«å ¥ããå¿ èŠããããŸãïŒã ããããPjaxReloaderã®ãããªç¬èªã®ãŠã£ãžã§ãããäœæããã«ã¯ããã¹ããšäžç·ã«çŽ10åããããŸãã æ£çŽãªãšãããç§ã¯è°è«ã«ããå€ãã®æéãè²»ãããŸãã
$js = "jQuery(document).on('pjax:success', '#$id', function() { jQuery.pjax.reload('$reloadSelector'); });"; $view->registerJs($js);
ãŠã£ãžã§ããã¯ã1ã€ã®è²¬ä»»ã®ãªããžã§ã¯ãã§ãã è¯ãæ¹æ³ã§ã¯ãOOPå ã®ãã¹ãŠã®ãªããžã§ã¯ãã1ã€ã®çŸ©åãè² ãå¿ èŠããããŸãããçŸå®ã®äžçã§ã¯åžžã«ããã§ãããšã¯éããŸããã èšäºã®ã³ã¡ã³ãã®ãªã¹ããšã³ã¡ã³ããè¿œå ããããã®ãã©ãŒã ã¯ãç°ãªããŠã£ãžã§ããã§ãã 1ã€ã«ã¯ä»ã®ãªãã·ã§ã³ãå«ããããšãã§ããŸãïŒãªãã·ã§ã³ïŒããæ··åšãããªãã§ãã ããã æåŸã«ã Vããªã³ã«ãŒã§ããããšãå¿ããªãã§ãã ããã å°ããªãŠã£ãžã§ããã1ã€ã®å€§ããªãŠã£ãžã§ããã«çµåã§ããŸãã ããã€ãã®å€§ããª1ã€ã«å·šå€§ã ãããŠãããã¯ãã¿ãŒã³ã®ç¯å²ãè¶ ããŸããã
åèš
ã¢ãã«ã«ã¯ç¶æ ãšããžãã¹ããžãã¯ãæ ŒçŽãããŸãã 圌女ã¯èªåã®ãµããžã§ã¯ããšãªã¢ã«é¢ãããã¹ãŠãç¥ã£ãŠããŸããã©ã®ã³ã³ãããŒã©ãŒãåŒã³åºããã©ã®è¡šçŸã衚瀺ãããã¯æ°ã«ããŸããã ã¢ãã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã®å€éšã§ç¬ç«ããç¬ç«ããã¯ã©ã¹ãšããŠã€ã³ã¹ã¿ã³ã¹åã§ããŸãã ã¢ãã«ã¯TDDã«ç°¡åã§ããããããã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ããžãã¯ãã¢ãã«ã«æ ŒçŽããå¿ èŠããããŸãïŒã³ã³ããŒãã³ãããµãŒãã¹ããªããžããªãªã©ãã¢ãã«ã§ããããšãæãåºããŸãïŒã
ãã¥ãŒã¯ãã¢ãã«ã«é¢ãããã¹ãŠã®æ å ±ãããã«ãã®ç¶æ ïŒããŒã¿ããŒã¹ããã¡ã€ã«ãRESTãªã©ïŒãæ£ç¢ºã«ä¿åããæ¹æ³ã å®å šã«ææ¡ããŠããŸãã ãã¥ãŒã¯ãã¢ãã«ãä¿åãããã£ãŒã«ãããã¥ãŒçšã«ãã©ãŒããããããããããã£ãä¿åããããã£ãŒã«ããèªèããŸãã ã¢ãã«ã«ã€ããŠã¢ã€ãã¢ãç¥ããªãå¯äžã®ããšã¯ãèšé²ãå€æŽãä¿åã®æ¹æ³ã§ãã ãã¥ãŒã«ã¯ãå¿ èŠãªãªããžã§ã¯ããšã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åããããŒã¿ãããã€ããŒãåéããæš©å©ããããŸãããã³ãŒãã®éè€ãé¿ããããã«ãå·¥å Žããã«ããŒããŠã£ãžã§ããã«æã£ãŠè¡ãããšããå§ãããŸãã
ã³ã³ãããŒã©ãŒã¯ãã¢ãã«ãŸãã¯ãã¥ãŒã«ã€ããŠäœãç¥ããŸããã ã³ã³ãããŒã©ãŒã¯ãã¢ãã«ãåŒã³åºãããã®ã¡ãœããã®çš®é¡ãç¥ã£ãŠããŸãããçŸæç¹ã§ã¢ãã«ã§å®éã«äœãèµ·ãã£ãŠããããè¡šããŠããŸããã ã³ã³ãããŒã©ãŒã¯ã¢ãã«ã§ããã€ãã®ã¢ã¯ã·ã§ã³ãèŠæ±ããŸãããã¢ãã«ãçæãããšã©ãŒïŒã€ãŸããã©ã³ã¿ã€ã ãšã©ãŒãšäŸå€ïŒãèªèããŠã¯ãªãããããããã€ã³ã¿ãŒã»ããããŠåŠçããããšã¯ãããŸããã ã³ã³ãããŒã©ãŒã¯ ãç¹å®ã®ãã¥ãŒïŒå®éãã³ã³ãããŒã©ãŒã¯1ã€ãŸãã¯è€æ°ã®ãã¥ãŒã®äžéšã§ããããïŒãéããŠè¡šç€ºãããã¢ãã«ãæäŸã§ããŸãïŒãã ããå¿ ãããå¿ èŠã§ã¯ãããŸããïŒã衚瀺ããã«ã¯ãã¥ãŒãå¿ èŠã§ãã 圌ãäœããéä¿¡ããªãã£ãå Žåããã¬ãŒã³ããŒã·ã§ã³ã¯ããã«é©åã«å¿çããéçºäžã®ã¢ããªã±ãŒã·ã§ã³ã«é¢ããŠã¯èªåã®äžéšã衚瀺ãããäŸå€ãã¹ããŒãããããªãã§ãã ããã ã³ã³ãããŒã©ãŒãåŠçã§ããå¯äžã®äŸå€ã¯NotFound 404ã§ãïŒ ã¿ã€ã403ã®æ®ãã®ãšã©ãŒã¯ããã£ã«ã¿ãŒïŒèŠæ±ã€ã³ã¿ãŒã»ãã¿ãŒïŒãŸãã¯ããã«ãŠã§ã¢ã§çæãããŸãã
ã³ã³ãããŒã©ã¯ãå°ãªããšãããŒã¿ãèªã¿åãããã«äœ¿çšããïŒãŸãã¯ãŸã£ãã䜿çšããªãïŒå¿ èŠããããŸã ã èªæžã¯ããŠã£ãžã§ãããšåæ§ã®ãªããžã§ã¯ãã«ãã£ãŠæŽçã§ããŸãã
ãŠã£ãžã§ããã«ã¯ã¢ãã«ãæäœããŠããŒã¿ããŒã¹ã«æžã蟌ãæš©å©ããããŸããããæœè±¡åããã«ããŒããã¡ã¯ããªãã¢ãã«ã¯ã©ã¹ãéããŠããŒã¿ããŒã¹/ãã¡ã€ã«ããããŒã¿ãèªã¿åãããã³ãã¬ãŒãã«æž¡ãããšãã§ããŸãã ãŠã£ãžã§ããã¯ãã¢ãã«ã€ã³ã¹ã¿ã³ã¹ãããããã¥ãŒïŒã¬ã€ã¢ãŠãã¢ãã«ïŒãŸãã¯ã³ã³ãããŒã©ãŒãã転éãããŠããªãå Žåãèªèº«å ã§ã¢ãã«ãã€ã³ã¹ã¿ã³ã¹åã§ããŸãã ããã¯èªã¿åãæäœã§ããããããŠã£ãžã§ããã¯ããŒã¿ãããã€ããŒãåéã§ããŸãã
çµè«ãšããŠãç§ã¯ãæ°ã«å ¥ãã®Habréã®èšäºããåŒçšãããã ãã§ãã èšäºã®åé ã®ã¢ãã«ã«é¢ããã»ã¯ã·ã§ã³ã§ãªã³ã¯ãæäŸããŸããã
äžéšã®äººã ã¯ãåªããç¬ç«ãããã¡ã€ã³ã¢ãã«ã®å¿ èŠæ§ã«ã€ããŠè©±ããæ··ä¹±ãæãã³ãŒããæžãç¶ããããããã¹ãŠã®æãè ãåã«ç¬ãã§ãããã 圌ããç¬ãããŠãã ããã çµå±ã®ãšãããæ··ä¹±ãç¶æãããã¹ãããå¿ èŠãããã®ã¯åœŒãã§ãã
ãããŠãäœæ²ãããªããšå ±ã«æ¥ãŸãããã«ïŒ ãã¹ãŠã«è¯ãïŒ