Smartyã¯ã©ã¹ãç¶æ¿ãã¦ä½¿ããããããã«æ¡å¼µãï¼php proã®æ¡å¼µã»ããã¢ããããªãããã¾ãåããªãã£ãã®ã§ã»ã»ã
拡張セットアップ - PHPプロ!マニュアル
ãã¡ããåèã«è²ã
ãã£ã¦ã¿ãã
åèã½ã¼ã¹
<?php require('Smarty.class.php'); class Smarty_Test extends Smarty { function Smrty_Test() { $this->Smarty(); $this->template_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/templates/'; $this->compile_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/templates_c/'; $this->config_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/configs/'; $this->cache_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/cache/'; $this->caching = true; $this->assign('app_name', 'Smarty Test'); } } ?>
å¼ã³åºãå
ã¯
vi smarty_test/htdocs/index.php
<?php require_once('../setup.php'); $smarty = new Smarty_Test(); $smarty->assign('name','Ryoff'); $smarty->display('index.tpl'); ?>
ã»ã¼ï¼ã£ã¦ãå ¨ã¦ï¼ãphp proããã½ã¼ã¹æã£ã¦ããã ãã§ã
ããåããã¨ã
Warning: Smarty error: unable to read resource: "index.tpl" in /usr/local/lib/php/Smarty/Smarty.class.php on line 1093 Fatal error: Smarty error: the $compile_dir 'templates_c' does not exist, or is not a directory. in /usr/local/lib/php/Smarty/Smarty.class.php on line 1093
ãããªã¨ã©ã¼ã§ã¦ãã¾ãããããã
var_dumpãã¦ã¿ãã¨ãã³ã³ã¹ãã©ã¯ã¿ãã¾ãå¼ã³åºãã¦ãªãæãã
ãªãã§ã ãããã£ã¦èª¿ã¹ãããã©ããããã㯠php4 ã®è¨è¿°æ¹æ³ãããã
php5ã§ã¯
Andante PHP、Smartyクラスを継承して拡張したい
âã®ãµã¤ãæ§ã«ãä¸è©±ã«ãªãã¾ããã
parent::__construct(); //親ã¯ã©ã¹åæå
ãããªæãã§è¦ªã®ã³ã³ã¹ãã©ã¯ã¿ãæç¤ºçã«å¼ã³åºãããããã
ãªã®ã§æ¸ãç´ãã¦ã¿ãã
vi smarty_test/setup.php
<?php require('Smarty.class.php'); class Smarty_Test extends Smarty { public function __construct() { parent::__construct(); //親ã¯ã©ã¹åæå $this->template_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/templates/'; $this->compile_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/templates_c/'; $this->config_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/configs/'; $this->cache_dir = '(ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹)/smarty_test/cache/'; $this->caching = true; $this->assign('app_name', 'Smarty Test'); } } ?>
åããã
é常ã«åå¼·ã«ãªãã¾ããã