Symfony 2ã«ã¯ãã©ãŒã ãæäœããããã®å®å šã«æ°ããã³ã³ããŒãã³ãããããŸããç§ã®ç¥ãéããPHPã®ãããã®ã©ã€ãã©ãªã®ã»ãšãã©ã¯æ©èœçã«ããå¯èœã§ããã°æ¡åŒµæã«ãç°¡åã«çœ®ãæããããŸãïŒãã¡ãããJavaScriptãæäœãããšãã«å°ããªæ¬ é¥ãèæ ®ããªãå ŽåïŒ ã ãã®ã³ã³ããŒãã³ãã®éçºã«ã¯2幎以äžããããŸãããã2009幎ãŸãã¯ãã以åã«å¥ã®å Žæã§èãå§ããŸããã æ°ããããŒãžã§ã³ããšã«ããã®ã³ã³ããŒãã³ãã¯ãŸããŸãå®å®ããŠãããSymfony 2.2ã®ãªãªãŒã¹ã§ã¯å®å šã«å®å®ããããŒãžã§ã³ãæåŸ ãããŠããŸãã
ãã®æçš¿ã¯Zend Framework 2 Form RFCã®ãªãªãŒã¹ã«æ§ããããŠããŸãããªããªãããã®éçºè ã¯å®éãç§ãã¡ããã§ã«ãã£ãããšã®å€ããããããã«æããããã§ãã ãã¡ãããZend Framework 2ã«ã¯ããã¬ãŒã ã¯ãŒã¯ã«ä»å±ããã³ã³ããŒãã³ãã®æ©èœãå®å šã«èæ ®ãããã©ãŒã ãæäœããããã®ã¬ã€ã€ãŒãå¿ èŠã§ããããšã¯èª°ã«ãšã£ãŠãæããã§ãã ãã®æçš¿ã®ç®çã¯ãSymfony2 Formsããããã®èŠä»¶ã«å®å šã«é©åããŠããããšã瀺ãããšã§ãã Symfony2ã«åºæã®æ©èœã¯ç°¡åã«åé€ã§ããŸãããã©ãŒã ããã³ãã¹ãŠã®æœè±¡åã¬ãã«ãåŠçããããã®ã³ãŒãã¯å®å šã«ç¬ç«ããŠããŸãã Zendã³ã³ããŒãã³ãã®æ©èœã®ãã€ã³ãã£ã³ã°ãµããŒããé£ãããããŸããã
éçºäžã«çºçããå¯èœæ§ã®ãããã¹ãŠã®äœ¿çšã·ããªãªãã«ããŒããããã©ãŒã ãæäœããããã®æ±çšã©ã€ãã©ãªãŒã®äœæã¯ãé£ãããã¹ãã§ãããé·ããŠé£ããã¿ã¹ã¯ã§ãããããã«ããŸã å®äºããŠããŸããã ã³ã©ãã¬ãŒã·ã§ã³ãšãããªãå ±åéçºã¯ãPHPããã®ããæè»ã§ã·ã³ãã«ãªãã©ãŒã 管çã®å®çŸã«åœ¹ç«ã€ã¯ãã§ãã
ãããããç§ãã¡ã®ä»äºã«åœ±é¿ãäžãããã©ãŒã ãåŠçããããã®ãã¬ãŒã ã¯ãŒã¯ãšã©ã€ãã©ãªã®éçºã«åå ãããã¹ãŠã®äººã«æè¬ããŠããã®æçš¿ãéå§ããŸãã 次ã«ãã¢ãŒããã¯ãã£èªäœã説æããåã«ããã©ãŒã ãæäœããããã®äŸ¿å©ã§æè»ãªã³ã³ããŒãã³ããèšèšããããã®éèŠãªåŽé¢ã玹ä»ããŸãã
ãã®æçš¿ã§ã¯ããã®ã³ã³ããŒãã³ãã®ããã©ãŒæ©èœãã®äœ¿çšäŸãèŠã€ããããšã¯ã§ããŸãããããã«é¢ããããã¥ã¡ã³ãããããŸã ã ãŸããããã§ã¯ããã¬ãŒã ã¯ãŒã¯ã«é¢ä¿ãªããã³ã³ããã¹ãã®å€ã§ããã®äœ¿çšã«é¢ããæ å ±ãèŠã€ããããšã¯ã§ããŸããã ãã®ãããªæ å ±ã¯ãããšãã°Gistã§èª¬æããå¿ èŠããããŸãã
圱é¿å
ãã©ãŒã ã³ã³ããŒãã³ãã¯ã symfony 1 ã Zend Framework 1 ã Django ã Ruby on Rails ã Strutsã JSFãªã©ãããŸããŸãªèšèªã§æžãããå€ãã®ãã¬ãŒã ã¯ãŒã¯ã®åœ±é¿ãåããŠããŸãã ããã«ã Formlets ã WUI ã iData ãLinksãCurryãCleanãªã©ã®é¢æ°åããã°ã©ãã³ã°èšèªçšã«èšè¿°ããããã©ãŒã ãæäœããããã®ã©ã€ãã©ãªãšã®é¡äŒŒç¹ãèŠã€ããããšãã§ããŸãã
äž»ãªåŽé¢
ãã©ãŒã ãæäœããããã®ã³ã³ããŒãã³ããèšèšããéã®éèŠãªåŽé¢ã¯æ¬¡ã®ãšããã§ãã
- å¢å ããæœè±¡å
- æ¡åŒµæ§
- æ§ææ§
- ã¿ã¹ã¯åé¢
- ã¢ãã«ãã€ã³ãã£ã³ã°
- åçæå
å®è£ ãããã¢ãŒããã¯ãã£ãããããã©ã®ããã«ã«ããŒããããè°è«ããåã«ããããã®ååŽé¢ãç°¡åã«èª¬æããŸãã
å¢å ããæœè±¡å
æœè±¡åã®ã¬ãã«ãäžãããšããã©ãŒã ã®ä»»æã®éšåïŒãã©ãŒã å šäœãå«ãïŒãååŸãããããããŒã¿æ§é ã«é 眮ããŠãåã³äœ¿çšã§ããããã«ãªããŸãã æ¥ä»ãéžæãããã©ãŒã ã«ã€ããŠèããŠã¿ãŸãããããã®ãã©ãŒã ã«ã¯ãæ¥ãæã幎ã§éžæããããã®3ã€ã®ããããããŠã³ãªã¹ãããããŸãã éå§ããã«ã¯ããã¹ãŠã®ããããããŠã³ãªãã·ã§ã³ã§HTMLãçæããã³ãŒããå¿ èŠã§ãã 次ã«ãã¢ããªã±ãŒã·ã§ã³ã®åœ¢åŒïŒããšãã°ãPHPã«ã€ããŠè©±ããŠããå Žåã¯DateTimeãªããžã§ã¯ãïŒãããã¬ãŒã³ããŒã·ã§ã³ã«é©ãã圢åŒã«ããŒã¿ãå€æããã³ãŒããå¿ èŠã§ãïŒãªã¹ãã§éžæããå€ãããŒã¯ããããïŒã ãã¡ãããéã®æé ãå¿ èŠã«ãªããŸãã ããã§ãããã€ãã®è¿œå ããŒã¿çšã«å¥ã®ããããããŠã³ãªã¹ããè¿œå ããå¿ èŠãããç¶æ³ãæ³åããŠãã ããã ãã®å Žåããã®ãªã¹ãã®ãã¹ãŠã®ã³ãŒããè€è£œããæ°ããèŠä»¶ã«é©åãããå¿ èŠããããŸãã
æœè±¡åã®å°å ¥ã«ãããã³ãŒãã®èšè¿°ãšåå©çšã«é©ããæ§é ãæäŸããããšã§ãã®åé¡ã解決ãããŸãã
æ¡åŒµæ§
æ¡åŒµæ§ã¯ãæœè±¡åã«é¢é£ãã2ã€ã®æŠå¿µã«åºã¥ããŠããŸãã
- ç¹æ®åã¯ãæœè±¡åã®è«ççãªã·ãŒã±ã³ã¹ã§ãã æ©èœãäžè¬åãããããŒã¿æ§é ã«æœè±¡åã§ããå Žåã¯ãããããããç¹æ®ãªæ§é ã«æ¡åŒµããããšãã§ããŸãã ããšãã°ãæéãã£ãŒã«ããè¿œå ããããšã§ãäžèšã®æ¥ä»éžæã®äŸãæ¡åŒµã§ããŸãã æ¥ä»ãéžæããããã«æ¢åã®ãã£ãŒã«ãã®æ©èœãæ¡åŒµããæ©äŒããªãã£ãå Žåãæ©èœã®å€§éšåãæžãçŽããªããã°ãªããŸããã
- äžçŽç©ã¯ç¹æ®åã®å察ã§ãã ããšãã°ãæ¢åã®ãã¹ãŠã®ãã£ãŒã«ããå€æŽããŠããããã®ãã£ãŒã«ããå¿
é ã§ããããšã瀺ãã¢ã¹ã¿ãªã¹ã¯ïŒ "*"ïŒã説æã«å«ãŸããããã«ããŸãã 䜿çšå¯èœãªãã¹ãŠã®ãã£ãŒã«ããæ¡åŒµããŠåãæ©èœãå®è£
ããå¿
èŠããããã ããã®ã¢ãããŒããç¹æ®åã§äœ¿çšããã®ã¯ããå®çšçã§ã¯ãããŸããã äžçŽç©ã䜿çšãããšãæ©èœãæ¢åã®ãªããžã§ã¯ãã«åå®çŸ©ããããšãªãæ¥ç¶ã§ããŸãã ããã«ããã®æ¹æ³ã§è¿œå ãããæ©èœã¯ãç¶æ¿ããªãŒã®ãã¹ãŠã®åãªããžã§ã¯ãã«ç¶æ¿ãããŸãã
æ¡åŒµæ§ãšã¯ãã€ãã³ããä»ããæ©èœã®ãã詳现ãªæ¡åŒµãæããŸãã ããã«ã€ããŠã¯åŸã§æ€èšããŸãã
ãªã³ã«ãŒ
æåŸã®äŸãåæãããšã ãã£ãŒã«ã ïŒæ€èšäžã®äŸã®ãããªè€åãã£ãŒã«ã ããŸãã¯å ¥åããã¹ããã£ãŒã«ãã®ãããªããªããã£ããªãã£ãŒã«ãïŒãšformsã®éã«ç¹å¥ãªéãããªãããšãããããŸãã ãããŠãã£ãŒã«ããšåœ¢ç¶
- ã¢ãã«ïŒé åãæ¥ä»ãæååãªã©ïŒããããã©ã«ãå€ãåãå ¥ããŸãã
- ãã¥ãŒã§äœ¿çšã§ããããã«å€ãå€æãã
- ãã©ãŒã HTML
- ãŠãŒã¶ãŒãå ¥åããå€ãåãå ¥ãã
- å€ãã¢ãã«åœ¢åŒã«æ»ã
- ããŒã¿ãæ€èšŒã§ãã
åãåºæ¬çãªããŒã¿æ§é ã䜿çšããŠãã£ãŒã«ããšãã©ãŒã ãå®è£ ã§ããŸãã ãªã³ã«ãŒã®è¿œå -ãã¹ããããæ§é ãè¿œå ã§ããããŒã«ïŒããªã³ã«ãŒããã¶ã€ã³ãã³ãã¬ãŒããåç §ïŒ-ä»»æã®è€éãªãã©ãŒã ãäœæã§ããŸãã ãã£ãŒã«ããšãã©ãŒã ãåºå¥ãã代ããã«ã ãã©ãŒã ãšãã®ã³ã³ããŒãã³ãã«ã€ããŠèª¬æããŸã ã ãã©ãŒã ã«åå«ã衚瀺ããããšããã«ã
- ããã©ã«ãå€ïŒé åãŸãã¯ãªããžã§ã¯ãïŒããã®åå«ã«æž¡ã
- å ¥åãããååã®å€ãé åãŸãã¯ãªããžã§ã¯ãã«è¿ããŸã
ã¿ã¹ã¯åé¢
äžèšã®ã¿ã¹ã¯ãããã€ãã®ç¹å®ã®ã°ã«ãŒãã«åããããšãã§ããŸãã
- ããŒã¿å€æ
- HTMLçæïŒãã¬ãŒã³ããŒã·ã§ã³ïŒ
- æ€èšŒ
- ããŒã¿ãã€ã³ãã£ã³ã°
ãããã®åã¿ã¹ã¯ã°ã«ãŒãã¯ãæ瀺çã«å®çŸ©ãããã€ã³ã¿ãŒãã§ã€ã¹ãæã€åå¥ã®ã³ã³ããŒãã³ãã«ãã£ãŠå®è£ ããå¿ èŠããããŸãã ããã«ããããããã®ã³ã³ããŒãã³ãã®ãããããç¬èªã®ãã®ã«çœ®ãæããããŸããããšãã°ããã¥ãŒãã³ãã©ãŒããŸãã¯æ€èšŒã¬ã€ã€ãŒãªã©ã眮ãæããããŸãã
ã¢ãã«ãã€ã³ãã£ã³ã°
ã»ãšãã©ã®å Žåããã©ãŒã ã¯å®çŸ©ã®ãã¡ã€ã³ã®ã¢ãã«ã§èšè¿°ãããæ§é ã«çŽæ¥æ¥ç¶ãããŸã ã ãŠãŒã¶ãŒãããã¡ã€ã«æ å ±ãéä¿¡ããäŸãèããŠã¿ãŸãããã ãã¹ãŠã®ãŠãŒã¶ãŒæ å ±ãããŒã¿ããŒã¹ã®å¥ã®ããŒãã«ã«ä¿åãããŠãããšããŸãã ããŒãã«ã«ã¯ããããã¡ã€ã«ã«å«ãŸãããããã㣠ãåããããã£ã«äœ¿çšãããããŒã¿ã®çš®é¡ ã ããã©ã«ãå€ ã ããŒã¿å ¥åå¶éã«é¢ããæ å ±ãæ ŒçŽãããŸãã çæ³çã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã«ã¯ãããšãã°Doctrine2 ORMãä»ããããŒã¿ããŒã¹å ã®ããŒãã«ãã€ã³ãã£ã³ã°ãšãšãã«ãå¿ èŠãªãã¹ãŠã®ããããã£ãæã€Profileã¯ã©ã¹ãå«ããå¿ èŠããããŸãã ãã®ã¯ã©ã¹ã«ã¯ãããŒãã«ã«ä¿åãããŠãããããå€ãã®ãããã¡ã€ã«ã«é¢ããæ å ±ãå«ãŸããŠããå ŽåããããŸããããšãã°ããããã¡ã€ã«ããŠãŒã¶ãŒã«ãšã£ãŠé¢å¿ã®ããç¹å®ã®ã¢ã€ãã ã®ã»ããã瀺ããŠããå Žåãªã©ã§ãã ç°¡åã«ããããã«ããããã®ã¢ã€ãã ã®ãªã¹ããæ§æãã¡ã€ã«ããååŸããŸãã
éåžžããªããžã§ã¯ããèšè¿°ããæ å ±ïŒ ã¡ã¿ããŒã¿ãšåŒã³ãŸãããïŒã¯ããã©ãŒã ã¬ã€ã€ãŒã§è€è£œããå¿ èŠããããŸãã éçºè ã¯ããã£ãŒã«ããå€æŽãããŠããªãããšãç·šéå¯èœãªãã£ãŒã«ãããã©ãŒã ã«HTMLãã£ãŒã«ãã«å¯Ÿå¿ãããŠã£ãžã§ããã衚瀺ãããŠããããšãäžéšã®ãã£ãŒã«ãã空ã®ãŸãŸã«ãªããªãããšãªã©ã確èªããå¿ èŠããããŸãã ãããã®ããšããããã©ãŒã ãäœæããã®ã¯ããªããããããä»äºã«ãªããŸãã
ã¢ãã«ãã€ã³ãã£ã³ã°ã¯ãéããçãããã«èšèšãããŠããŸãã 次ã®2ã€ã®ã¢ã€ãã¢ã«åºã¥ããŠããŸãã
- éè€ããã³ãŒããèšå®ã®æ°ãæžããããã«ããã©ãŒã ã®äœæäžã«æ¢åã®ã¡ã¿ããŒã¿ã䜿çšããŸãã
åçæå
æåŸã«ãªããŸãããããããã¯ãã©ãŒã ã®åçãªåäœã§ãã ãã©ãŒã ã®ã³ãŒãããµãŒããŒã«å®å šã«å®è£ ããããŠãŒã¶ãŒãå ¥åããããŒã¿ã®ã»ãã¥ãªãã£ãã§ãã¯ãå³å¯ã«å®çŸ©ãããæ§é ã®äžã§å®è¡ãããŠããæ代ã¯çµãããŸããã ä»æ¥ã§ã¯ãJavaScriptã䜿çšããŠã¯ã©ã€ã¢ã³ãåŽã®ãã©ãŒã ãå€æŽããã·ã¹ãã ã®äœ¿ãããããåäžãããããšãæµè¡ããŠããŸãã
ããŒãã«ã®åœ¢ã§ãã©ãŒã ãæ³åããŠãã ããã ååã«ã¯åãã¿ã€ãã®ãã£ãŒã«ãããããåè¡ã¯ãµãŒããŒäžã®ãªããžã§ã¯ããè¡šããŸãã ãã©ãŒã ã«ã¯ãè¡ãè¿œå ãŸãã¯åé€ã§ãããã¿ã³ããããŸãã ããããã¹ãŠã«ããããã©ãŒã ãæ€èšŒããå¯èœæ§ãæ®ã£ãŠããã¯ãã§ãããã©ãŒã ã¯ãµãŒããŒäžã§æ£åžžã«åŠçãããå¿ èŠããããŸãã
ãã®ãã©ãŒã ãå®è£ ããããã«ãåçãªåäœãèæ¡ãããŸããã ããã«ããããã®äœ¿çšã¯æ¯èŒçåçŽãªè¡šåœ¢åŒã«éå®ãããŸããã ã¯ã©ã€ã¢ã³ãåŽã§è¡ãããæ§é ã®å€æŽã«å¿çãããã©ãŒã ãäœæã§ããŸãã æ®å¿µãªããããã®ãããªã¡ã«ããºã ã®é¢é£æ§ã«ããããããããã®åé¡ã¯ã»ãšãã©ã®ã©ã€ãã©ãªã§è§£æ±ºãããŠããŸããã
é«ã¬ãã«ã®ã¢ãŒããã¯ãã£
ãã©ãŒã ãæäœããããã®Symfony2ã®ã¬ã€ã€ãŒã¢ãŒããã¯ãã£ã®æŠèŠã説æããŸãã ãã®ç€ç³ã¯ãã©ãŒã ã³ã³ããŒãã³ãã§ãã ãã®ã³ã³ããŒãã³ãã¯ããã©ãŒã ã®ã³ã³ãã€ã«ãšåŠçã®åºç€ãå®è£ ããSymfony2 ã€ãã³ããããŒãžã£ãŒã䜿çšããŠå éšã€ãã³ããåŠçããŸãã ãã®ã³ã³ããŒãã³ãã®äžã«ã¯ããã©ã°ã€ã³æ¡åŒµæ©èœã®ã¬ã€ã€ãŒããããŸãã
- ã«ãŒãã«ã¬ãã«ã®æ¡åŒµæ©èœã¯ããã¬ãŒã ã¯ãŒã¯ã«å®è£ ããããã£ãŒã«ãæ§é ã®èª¬æãæäŸããŸãïŒãã©ãŒã ã¿ã€ããšåŒã³ãŸãããïŒã
- ãã©ãŒã å ã®ãŠãŒã¶ãŒå ¥åãæ€èšŒããã«ã¯ ã æ€èšŒã®æ¡åŒµãå¿ èŠã§ãã
- DIæ¡åŒµã«ããã äŸåé¢ä¿ã³ã³ããã䜿çšã§ããŸãã
- CSRFæ¡åŒµæ©èœã¯ããã®ååã瀺ãããã«ããã©ãŒã ã«CSRFä¿è·ãè¿œå ããŸãã
- Doctrine2æ¡åŒµæ©èœïŒ Doctrine Bridgeã§æäŸïŒã¯ããã©ãŒã ã§äœ¿çšãããªããžã§ã¯ãã¡ã¿ããŒã¿ãååŸã§ããããã«ããDoctrineåºæã®ããããããŠã³ãªã¹ããšã³ã³ããŒãã³ããè¿œå ããŸãã
äžäœã¬ãã«ã«ã¯ãHTML-Iã®åœ¢æãå®è£ ããã³ã³ããŒãã³ããå«ãŸããŠããŸãã ããã©ã«ãã§ã¯ãSymfony2ã«ã¯ãã®ãããª2ã€ã®ã³ã³ããŒãã³ãããããŸãã1ã€ã¯Twigçµç±ã§ãã©ãŒã ãã¬ã³ããªã³ã°ããããïŒ Twig bridgeã§æäŸ ïŒããã1ã€ã¯å€ãè¯ãPHPã§ã¬ã³ããªã³ã°ããããã§ãïŒ FrameworkBundleã§æäŸ ïŒã
ããããããã®ã¢ãŒããã¯ãã£ã®æãèå³æ·±ãæ©èœã¯ãä»»æã®ã³ã³ããŒãã³ãã亀æã§ããããšã§ãã ãã©ãŒã ãZendã®æ€èšŒã³ã³ããŒãã³ãã䜿çšããããã«æ¡åŒµæ©èœãäœæã§ããŸãã ãŸããSmartyãŸãã¯ãã®ä»ã®ãã³ãã¬ãŒããšã³ãžã³ãä»ããŠã¬ã³ããªã³ã°ãå®è£ ãããã¥ãŒã³ã³ããŒãã³ããäœæããããšãã§ããŸãã ã«ãŒãã«ã¬ãã«ã®æ¡åŒµæ©èœãåé€ããŠãåçŽãªãã£ãŒã«ãã®åºæ¬çãªãã©ãŒã ã¿ã€ããèšè¿°ããããšãã§ããŸãã åºã«ãªãã€ãã³ããã£ã¹ãããã£ã§ããã EventDispatcherInterfaceã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããã³ã³ããŒãã³ãã«çœ®ãæããããšãã§ããŸã ã ããã¯ãå€å°ã®äžäŸ¿ãã«ãããããããæè»æ§ã«åªããå©ç¹ããããããŸãã
äœã¬ãã«ã®ã¢ãŒããã¯ãã£
ãã®ã»ã¯ã·ã§ã³ã§ã¯ããã©ãŒã ã³ã³ããŒãã³ãã®å éšã¢ãŒããã¯ãã£ã«çŠç¹ãåœãŠãŸãã åè¿°ã®ããã«ããã©ãŒã ãšãã®ãã¹ãŠã®éšåã¯ãããªã³ã«ãŒãèšèšãã¿ãŒã³ãå®è£ ããåãããŒã¿æ§é ã§è¡šç€ºãããŸãã Formã³ã³ããŒãã³ãã§ã¯ããã®æ§é ã¯FormInterfaceã€ã³ã¿ãŒãã§ãŒã¹ã«ãã£ãŠèšè¿°ãããŸãã ãã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããäž»ãªã¯ã©ã¹ã¯Formã¯ã©ã¹ã§ããã®ã¯ã©ã¹å šäœã§æ©èœãã3ã€ã®ã³ã³ããŒãã³ãã䜿çšããŸãã
- ããŒã¿ããããŒã¯ããã©ãŒã ããŒã¿ããã®åã«åé ããŸãã ããã«ãåäŸããããŒã¿ãåéããŠããŒã¿ã圢æããããšã¯ããã®ã³ã³ããŒãã³ãã®è²¬ä»»ã§ãã
- ååã瀺ããšããã ããŒã¿ã³ã³ããŒã¿ãŒã® 2ã€ã®ãã§ãŒã³ã¯ ãç°ãªãè¡šçŸã®å€ãå€æããŸãã ããŒã¿ã³ã³ããŒã¿ãŒã¯ããããè¡šãããã«äœ¿çšããã圢åŒã«é¢ä¿ãªããã¢ããªã±ãŒã·ã§ã³ãå³å¯ã«å®çŸ©ããã圢åŒã§å€ãåãåãããšãä¿èšŒããŸãã
- ã€ãã³ããããŒãžã£ã䜿çšãããšããã©ãŒã åŠçã®æå®ã®æ®µéã§ç¹å®ã®ã³ãŒããå®è¡ã§ããŸãã ãã®ã¢ãããŒãã«ããããã©ãŒã æ§é ãåä¿¡ããŒã¿ã«é©åããããããããã®éåžžã«åä¿¡ããŒã¿ãé€å€ããããæ€èšŒãŸãã¯å€æŽãããã§ããŸãã
ãããã®ãã¹ãŠã®ã³ã³ããŒãã³ãã¯ã Formãªããžã§ã¯ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒã«æž¡ããã ãã©ãŒã ã®äœæåŸã«å€æŽããããšã¯ã§ããŸãããããã¯ããã©ãŒã ã®ç¶æ ã«æãŸãããªãå€æŽãåŒãèµ·ããå¯èœæ§ãããããã§ãã Formãªããžã§ã¯ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒã®ã€ã³ã¿ãŒãã§ã€ã¹ã¯éåžžã«è€éãªã®ã§ã ãã©ãŒã ã³ã³ã¹ãã©ã¯ã¿ãŒ ïŒFormBuilderïŒãå®è£ ãããŠããããããã®ãªããžã§ã¯ãã®ã€ã³ã¹ã¿ã³ã¹ã®äœæãç°¡åã«ãªã£ãŠããŸãã
ãã©ãŒã ã®ãã¥ãŒã¯ããã¥ãŒãèšè¿°ããããŒã¿æ§é ã§ãã ã€ãŸãããã³ãã¬ãŒãã§çŽæ¥Formã¯ã©ã¹ãåŒã³åºã代ããã«ã FormViewã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã䜿çšããŸãã ãã®ãªããžã§ã¯ãã«ã¯ããã©ãŒã ã®HTMLèŠçŽ ã®ååå±æ§ãIDãªã©ããã¬ãŒã³ããŒã·ã§ã³å°çšã®è¿œå æ å ±ãæ ŒçŽãããŸãã
以äžã®UMLå³ã¯ãã¢ãŒããã¯ãã£ã®æ¬è³ªã瀺ããŠããŸãã
ãã®å³ãããããããã«ããã©ãŒã ã®ã©ã€ããµã€ã¯ã«ã¯3ã€ã®ç°ãªãè¡šçŸã§æ§æãããŠããŸãã
- äœæããããšããã©ãŒã ã¯FormBuilderãªããžã§ã¯ãã®éå±€ãšããŠè¡šãããŸã
- ã³ã³ãããŒã©ãŒã§ã¯ããã©ãŒã ã¯Formãªããžã§ã¯ãã®éå±€ã§è¡šãããŸã
- ãã¬ãŒã³ããŒã·ã§ã³ã¬ãã«ã§ã¯ã FormViewãªããžã§ã¯ãã®éå±€ã§è¡šãããŸãã
ãã¬ãŒã³ããŒã·ã§ã³çšã«ãã©ãŒã ãã¶ã€ããŒãæ§æããã®ã¯ããªãé¢åãªã®ã§ãSymfony2ã¯ãåºæ¬èšå®ãæ¢ã«å®è£ ããŠãããã©ãŒã ã®åºæ¬ã¿ã€ããå®è£ ããŸãã ãã©ãŒã ã¿ã€ãã¯åçç¶æ¿ããµããŒãããŸãã ã€ãŸãããã©ãŒã ã³ã³ã¹ãã©ã¯ã¿ãŒã«æž¡ããããªãã·ã§ã³ã«åºã¥ããŠãããŸããŸãªåºæ¬åãæ¡åŒµã§ããŸãã 次ã®å³ã¯ãSymfony2ã«å梱ãããŠãããã¹ãŠã®ã¿ã€ãã瀺ããŠããŸãïŒã«ãŒãã«ã«å梱ãããŠããç·ã§ããŒã¯ãããã¿ã€ããè¿œå ã®ãã³ãã«ãé»è²ã®å ŽåïŒ
åè¿°ã®äžçŽç©ã¯ãããããåæ¡åŒµãšããŠSYmfony2ã«å®è£ ãããŠããŸãã ãããã®æ¡åŒµæ©èœã¯ãæ¢åã®çš®é¡ã®ãã©ãŒã ã«æ¥ç¶ããäœããã®åäœãè¿œå ã§ããŸãã ããšãã°ãSymfony2ã«ã¯ãããã©ãŒã ãã¿ã€ãïŒããã³ãã®çµæããã®ã¿ã€ããç¶æ¿ãããã¹ãŠã®ã¿ã€ãïŒã«CSRFä¿è·ãè¿œå ããããã®æ¡åŒµæ©èœããããŸãã
ãã©ãŒã ãã¡ã¯ããªã¯ ãããŒããããæ¡åŒµæ©èœããåéå±€ãååŸããããã䜿çšããŠFormBuilderããã³FormViewãªããžã§ã¯ããã«ã¹ã¿ãã€ãºããŸã ã ãã®æ®µéã¯å¶åŸ¡ã§ããããšã«æ³šæããããšãéèŠã§ãã ããšãã°ãã¿ã€ãã choice ãã䜿çšãããšãèšå®ã§å±æ§ã choices ããæå®ã§ããŸããããã«ã¯ã衚瀺ããããªãã·ã§ã³ã®ãã¹ãŠã®å€ãå«ãŸããŸãã
Formã³ã³ããŒãã³ãã¿ã€ãã®äºæž¬åã«ã¯ããã1ã€ã®ããªãéèŠãªæŠå¿µããããŸãã ãããã®ãäºæž¬åãã¯ããã©ãŒã ãå²ãåœãŠãããŠããå®çŸ©é åã®ãªããžã§ã¯ãããååŸãããã¡ã¿ããŒã¿ã«åºã¥ããŠããã©ãŒã ãã£ãŒã«ãã®ã¿ã€ããšãªãã·ã§ã³ãäºæž¬ããããšããŸãïŒãã¡ãããåºå®ãããŠããå Žåãé€ãïŒã ããšãã°ããªããžã§ã¯ãã®ããããã£ã®ããããã«Tagãªããžã§ã¯ãéã®1察å€ã®é¢ä¿ãå«ãŸããŠããå Žåãåäºæž¬åã¯ãã®ããããã£ã®ãã®ãã©ãŒã ãã£ãŒã«ããèªåçã«æ§æããè€æ°ã®å€ãéžæã§ããæ©èœãæã€éžæãã£ãŒã«ãã«ãªããŸãã Tagãªããžã§ã¯ãã®ãã¹ãŠã®ã€ã³ã¹ã¿ã³ã¹ããã®ãã£ãŒã«ãã®ãªãã·ã§ã³ãšããŠäœ¿çšããŸãã åæ§ã®æŠå¿µãDjangoãã¬ãŒã ã¯ãŒã¯ã®ModelFormsã§äœ¿çšãããŠããŸã ã 確ãã«ã倧ããªéãã1ã€ãããŸããåäºæž¬åã¯ãORMã ãã§ãªããã¹ãŠã®ãªããžã§ã¯ãã¡ã¿ããŒã¿ã«ãã£ãŠæäŸãããã¡ã¿ããŒã¿ã䜿çšããŸãã Symfony2ã«ã¯3ã€ã®ã¿ã€ãã®äºæž¬åãä»å±ããŠããŸãã1ã€ã¯Doctrine2ã«ãã£ãŠæäŸãããã¡ã¿ããŒã¿ã䜿çšãããã1ã€ã¯æäŸãããpropelã䜿çšãããã1ã€ã¯æ€èšŒã«ãŒã«ã䜿çšããŸãã
äžèšã®æŠå¿µã¯ã次ã®UMLå³ã§èª¬æã§ããŸãã
ãããã«
ãã®æçš¿ã§ç€ºãããã£ãã®ã¯ãSymfony2 Formã³ã³ããŒãã³ãã«ã¯ããã©ãŒã åŠçã®å€ãã®éèŠãªåŽé¢ãã«ããŒããé©åã«èšèšãããã¢ãŒããã¯ãã£ãããããšã§ãã
ãã®ã¢ãŒããã¯ãã£ã¯ãäžååãªã¬ãã«ã®æœè±¡å ã ç¹æ® å ãããã³äžçŽç©ã®åé¡ã解決ãããã©ãŒã ã®ã¿ã€ããšãã®æ¡åŒµã®ç¶æ¿ã®åçããªãŒãæäŸããŸãã ãã©ãŒã ãåŠçããã¿ã¹ã¯ããã®ãã¹ãŠã®èŠçŽ ã«åæ£ããããšã«ããã æ§æã®åé¡ã解決ããŸãã ãŸããã³ã³ããŒãã³ãéã§ã¿ã¹ã¯ãæ確ã«åé¢ã§ãããããç¬èªã®ã¿ã¹ã¯ã«çœ®ãæããããšãã§ããŸãã ãã©ãŒã ã®äœææã«å®çŸ©ãã¡ã€ã³ã®ãªããžã§ã¯ãã®ã¡ã¿ããŒã¿ã䜿çšããŠã説æãããŠããã¢ãŒããã¯ãã£ã¯ãããã®ã¢ãã«ãžã®ããŒã¿ãã€ã³ãã£ã³ã°ãå®è£ ããããŒã¿ã®çŽæ¥èªã¿åããšæžã蟌ã¿ãå¯èœã«ããŸãã ãŸãã åçãªåäœãç¡èŠããŸããã§ãããããšãã°ããã³ãã©ãŒã䜿çšããŠãã©ãŒã ã®åŠçäžã«çºçããç¹å®ã®ã€ãã³ãã远跡ããããŒã¿ã®æ€èšŒããã£ã«ã¿ãŒåŠçãè¡ãããšãã§ããŸãã
ã«èå³ããããŸããïŒ ã³ãŒããåŠã¶ ã ããã§å®éšããŠãã ãã ã ãããŠããæ°ã«å ¥ãã®ãã¬ãŒã ã¯ãŒã¯ã«çµ±åããã®ãæäŒã£ãŠãã ããã
翻蚳è ããïŒãã®èšäºã®ç¿»èš³ã¯ååšããŸãããé«å質ã§ã¯ãªããšæãããŸããã ã¯ããããã¯çããªããšæããŸãã 翻蚳ã§ã¯äžæ£ç¢ºãªå¯èœæ§ããããŸãã®ã§ãPMã§ãææããã ããå Žåã¯æè¬ããããŸãã ãæž èŽããããšãããããŸããã