fuelphpã®Viewã®ä½ãä»ã²ã¨ã¤ç©è¶³ããªãæããªãã¨ããã¦ã¿ã
ãããªå¤§ãã話ã§ã¯ãªããã§ãããã
fuelphpã®Viewæ©è½ãã¹ããã¼ã³ã³ããã¼ã©å¼·ä¾åçæ£è ãªèªåã¨ãã¦ã¯ããªãå¬ããæããªãã§ãã,ãã£ã±ãã¾ã ã²ã¨ã¤ç©è¶³ããªãæã
fuelphpã®View
ãfuelphpã®Viewã¯ç´ æ´ãããããªããViewã¯ã©ã¹ãViewã¯Controllerã®ãã¡æ©è½ãã§ã¯ãªããfuelã«ããã¦ã¯Viewã¨Controllerã«å ¨ãä½ã®é¢é£æ§ããªããããã ãã§ãååã«ç´ æ´ãããã
ããªã¼ããã¼ãã·ã¹ãã ãå©ç¨ãã¦éçã¯ã©ã¹ã®å¤æ°ã«ã©ãããã§ãã¬ã·ã¬ã·å¤ãåºãå ¥ãåºæ¥ãã(ãã§ãããã£ã¦Globalå¤æ°ã¨ä½ãéãã®?)ãå©ä¾¿æ§ã¯ãã£ã¡ãã¨ç¢ºä¿ãããã¾ã¾ãControllerã¨Viewã¨ã®åãé¢ãã«è¦äºæåãã¦ããããã$thisãããªã(âããéè¦)ã
ãããªããã ããViewModelã®å®è£ ãã»ãã¨ã«ç°¡åãViewModelã¯ã©ã¹ã£ã¦ã®ãæä¾ããã¦ã¦,ããã使ãããããã¯ãã¦ãã,ãããªãããç¡ãã¨ãèªåã§ViewModelãå®è£ ã§ããããã§,ããããè¨è¨ã¯ã¹ããã¼ã³ã³ããã¼ã©å¼·ä¾åçã«ã¯é常ã«å©ããæã
fuelphpã®Viewã®æ®å¿µãªæ
ãfuelphpã®Viewã¯ã©ã¹ã«ã¯,ã¬ã¤ã¢ã¦ãã®æ©è½ããªããè¦ã¯Viewã¯ã©ã¹ã£ã¦ã®ã¯åä¸ã®ãã³ãã¬ã¼ããã¡ã¤ã«ã®ã¬ã³ãã©ã¼ã¨ãã¦è¨è¨ããã¦ãããã¡ã¤ã³ã®ã¬ã¤ã¢ã¦ããã¡ã¤ã«ã«,ã³ã³ããã¼ã©ã¢ã¯ã·ã§ã³åä½ã®ãã³ãã¬ã¼ããã¡ã¤ã«ãå²ãå½ã¦ã¦â¦ã¿ãããªViewã®é層åãã¯è¤æ°ã®Viewã¯ã©ã¹(ã®ãªãã¸ã§ã¯ã)ãçµã¿åããã¦å®ç¾ãããã¨ã«ãªãããããå¾®å¦ã«åä»ã ã
ãä¸å¿TemplateControllerãªãã¦ãã®ãç¨æããã¦ã¯ããã®ã ããããã¯Controllerãããã ã¨æå³ãç¡ãããªããã¾ãä¾ã«ãã£ã¦$thisã ãControllerå
ã§$this->view
ã¨ãæ¸ããªãããªããªããããã ãã¯æ¬å½ã«é¿ãããããã®ã¸ããå
±æã§ãããã¯ã¨ãããã¨ãã¦,ãã£ããViewã¨Controllerãåé¢ããã®ã«,ãªãã¾ãControllerã«Viewå¦çã®æ綱ã渡ããªãããªããã®ããã¨è¨ã話ã
ããããããããViewã¯ã©ã¹ã¯åä¸ãã³ãã¬ã¼ããã¡ã¤ã«ã®ã¬ã³ãã©ã¼ã¨ãã¦è¨è¨ããã¦ããããã«è¦ªã¬ã¤ã¢ã¦ã->åã¬ã¤ã¢ã¦ãã®å½¢ã§ã¢ã¯ã»ã¹ããªããã°ãªããªãããããé常ã«æ°æã¡æªãããã¼ã¿ã®è¨è¨çã«ç解ã§ããªãã¯ãªããã ã,使ãå´ã®å¿çã¨ãã¦ã¯åã¬ã¤ã¢ã¦ã->親ã¬ã¤ã¢ã¦ãã®ãã¼ã¿æ§é ã好ã¾ããã¨æãã親ã¬ã¤ã¢ã¦ãçµç±ã§ãã,åã¬ã¤ã¢ã¦ãã«ã¢ã¯ã»ã¹åºæ¥ãªãã®ã¯ç ©éã ãã親ã¬ã¤ã¢ã¦ãã¯é¡ããã°åã¬ã¤ã¢ã¦ãã®ããããã£çåå¨ã§ãã£ã¦æ¬²ããã
ãªãã¨ããã¦ã¿ãã
ãfuelphpã触ãã ãã¨ãã®ã¸ãã®æãã©ããã¦ãæ°ã«ãªããã¨ãããã¾ãæ£ç´ã©ã£ã¡ã§ãããã£ã¡ãã©ã£ã¡ã§ããããã ã,ãªãã¨ãªãã¢ã¤ã¢ã¤ããã¾ã¾é²ããã®ãæ°ãä¹ããªãã
ã第ä¸,æ°ããfuelphpã§ããã¸ã§ã¯ããæ§ç¯ãå§ãã度ã«ãããªãããããªãåé¡ã§æ©ãã§ä½æ¥ãæ¢ã¾ãã®ã¯é常ã«ãã£ãããªãã®ã§,ããããã£ãæ¸ãã¦ããã°ãã,ã£ã¦äºã«ãªã£ã¦ãã£ã¨æ¸ãã¦ã¿ãã
https://gist.github.com/mikakane/5473969
Layoutã¯ã©ã¹ãã¨è¨ãå½¢ã§å®è£ ãLayoutã¯ã©ã¹ã¯ç¶æ¿é¢ä¿ã®ãªãæ®éã®ã¯ã©ã¹ã§,get/setã§éçã¯ã©ã¹å¤æ°ã«å¤ãæ ¼ç´ã§ããããã«ãªã£ã¦ãããããã親ã¬ã¤ã¢ã¦ãã§å©ç¨å¯è½ã¨ãªãå¤æ°ã¨ãªãããã¨å人çã«ã¯setã«å ãã¦é åè¦ç´ ã«å¤ã追å ããaddã¨ããã¡ã½ãã®åå¨ãããã¯é常ã«ä¾¿å©ãªããããªããã£ã¦æã£ã¦ããã
ãä¸å¿,ä¸è¬çãªViewã¨ãããã®ã®å½¢ã«åããã¦Layout::set
ããå¤ã¯ã親ã¬ã¤ã¢ã¦ããã¡ã¤ã«å
ã§$var
å½¢å¼ã®ã¢ã¯ã»ã¹ãå¯è½ã¨ãªã£ã¦ããã,åºæ¬çã«ã¯ã©ãããã§ãLayout::get
ã§ã¢ã¯ã»ã¹å¯è½ãªã®ã§,ããã¯æ£ç´å¿
è¦ãªãããããªããã£ã¦æã£ã¦ããã
ãã¨ã«ããããã§ããªãã¨ãããããã解æ¶ããããã¨è¨ãæãããªã¼ãã³ã½ã¼ã¹ãªãã ãããã«ãªã¯ã¨ã¹ããã¦ã¿ãããã¨ãæã£ããã©,æ£ç´å¿ è¦æ§ãå ¨ãæããªãã,ãªã¼ããã¼ããªã®ã«ã¯ã©ã¹2åå®ç¾©ãã¦ãã¨ãååã ãã§ãªããæ°ãä¹ããªãã£ããããããã°ã®ãã¿ã¨ãã¦æ¶åãããã¨ã«ããã
ããã£ã¨ç´°ããäºãè¨ãåºãã°,ããªãã§set_filenameã¡ã½ãã§viewsãã£ã¬ã¯ããªããã¼ãã³ã¼ãããã®ã(extensionã¯ã¯ã©ã¹å¤æ°ãªã®ã«â¦)ãã¨ãè²ã ã¨ãããã ããã©ãããã¯ã¾ãå¥ã®æ©ä¼ã«ã§ãã