ã¡ã¼ã«éä¿¡æã«(Viewã®)ãã³ãã¬ã¼ããã¡ã¤ã«ã使ãæ¹æ³
CakePHP 1.2.0.7125 RC1.ã使ã£ã¦ãã®ã§ãããã¡ã¼ã«éä¿¡æã«ã¡ã¼ã«æ¬æããã³ãã¬ã¼ãåãã¦ãããèªã¿è¾¼ãã§éä¿¡ãããã¨æããæ¤ç´¢ããã¨ãããcontrollerã®renderã®å 容ãåºåããob_get_clean(); ã®åå¨ãç¥ãããããããã£ã¦ããã§ããã©ãããã¾ããããªããã¡ã¼ã«æ¬æã®å 容ã¾ã§ç»é¢ã«åºåããã¦ãã¾ã£ãã
é§ç®ã ã£ãã³ã¼ãã¯ãããªæã
ob_start();
$this->render(null, 'email', 'infomail');
$body = ob_get_clean();
$bodyã«ã¡ã¼ã«æ¬æãå
¥ãããããã¡ã¼ã«éä¿¡é¢æ°ã«æ¸¡ãã¾ãã
ãã®ob_get_cleanã§ç´åã¾ã§ã®renderã®å
容ãåºåãã¦å¤æ°ã«å
¥ãããã¨ãåºæ¥ã¾ãã
ãã®å¾ã該å½ã¢ã¯ã·ã§ã³ã®viewã®ãã¡ã¤ã«ãå¼ã°ãã¦ç»é¢ã«htmlåºåããã¾ãã
ãã¾ãããã¨ãããªæãã«ãªãã®ã§ãããä»åã®Cakeã®ãã¼ã¸ã§ã³ã ã¨$this->renderãã¦ob_get_cleanãèªãã§ãå 容ãå¤æ°ã«å ¥ãããç»é¢ã«è¡¨ç¤ºããã¦ãã¾ãã
ã¨ãããã¨ã§ãcake/libs/controller/controller.phpã®ä¸ã®renderã¡ã½ããã®ã³ã¼ããèªãã§ã¿ãããä¸è¨ã®ããã«ãªã£ã¦ãã
function render($action = null, $layout = null, $file = null) { éä¸çç¥ã $this->autoRender = false; $this->output .= $View->render($action, $layout, $file); return $this->output; }
renderã¯booleanãè¿ã£ã¦ãããã¨æã£ã¦ããããã³ãã¬ã¼ããã¡ã¤ã«ã®å
容ãreturnãã¦ããããã
ããã¦ã$this->outputãviewã§å¼ã³åºããã¦ç»é¢ã«åºåãããã
ã¨ãããã¨ã§ãä¸è¨ã®ããã«ãã¦ã¿ã
$this->set("inputdata",$data); $content = $this->render(null,'email', 'infomail'); $this->output = '';
ä¸è¨ã®ã³ã¼ãã§ã¯ããã³ãã¬ã¼ãã«æ¸¡ãinputdataã«åºåãããå
容ã®$dataãã»ããããrenderã¡ã½ããã®returnå¤ãã¡ã¼ã«æ¬æã«è©²å½ãã$contentã«å
¥ãããæå¾ã«ãrenderå
ã§$this->outputã«å
¥ã£ãã¡ã¼ã«æ¬æã®å
容ãæ¶å»ã
ããã¦ãã®å¾ã«ãviewã§è©²å½ã¢ã¯ã·ã§ã³ã®ãã³ãã¬ã¼ããå¼ã°ãã¦ã$this->outputã«ç»é¢è¡¨ç¤ºç¨ã®htmlãã»ããããã¦ç»é¢ã«åºåãããã
ä¸è¨ã®ã³ã¼ãã®å ´åãrenderã®ç¬¬ï¼å¼æ°ã§ã¬ã¤ã¢ã¦ããã¡ã¤ã«email.ctpãå®ç¾©ãã第ï¼å¹æ°ã§ãã³ãã¬ã¼ããã¡ã¤ã«infomail.ctpãå®ç¾©ãã¦ããã®ã§ãapp/view/layouts/email.ctpã¨ãapp/view/ã¢ãã«å/infomail.ctpãç¨æãã¦ããã
app/view/layouts/email.ctpã§ã¯ãä¸è¨ã®ãããªå 容ãå®ç¾©
<?php echo $content_for_layout; ?> ----------------------------------- xxxx@xxxxxxx.jp ã·ã°ããã£ã®å 容 -----------------------------------
$conent_for_layoutã«ãä¸è¨ã®ãã³ãã¬ã¼ãã®å 容ãã»ããããã
app/view/ã¢ãã«å/infomail.ctpã®å 容
ãåãåããé ããããã¨ããããã¾ãã ä¸è¨ããåãåããå 容ã§ãã ä¼ç¤¾åï¼<?php echo $inputdata['ã¢ãã«å']['companyname']; ?> ååï¼<?php echo $inputdata['ã¢ãã«å']['username']; ?>
ä¸è¨ã®ãã³ãã¬ã¼ãã¯ãã³ã³ããã¼ã©ã¼ã§
$this->set("inputdata",$data);
ã¨ãã¦ãã¦ã$dataã«$data['ã¢ãã«å']['companyname']ã¨ã»ããããã¦ããã®ãåæã§ãã