PHP/Smarty ¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×(No.3)
- ¥Ð¥Ã¥¯¥¢¥Ã¥×°ìÍ÷
- º¹Ê¬ ¤òɽ¼¨
- ¸½ºß¤È¤Îº¹Ê¬ ¤òɽ¼¨
- ¥½¡¼¥¹ ¤òɽ¼¨
- PHP/Smarty ¤Ø¹Ô¤¯¡£
- 1 (2010-09-06 (·î) 11:47:19)
- 2 (2010-09-06 (·î) 11:50:43)
- 3 (2010-09-06 (·î) 19:35:37)
- 4 (2010-09-09 (ÌÚ) 20:33:21)
[PHP]
Smarty´ØÏ¢¥ê¥ó¥¯
- [www.smarty.net]smarty APIÆüËܸì¥Þ¥Ë¥å¥¢¥ë
- [CodeZine]WEB¥·¥¹¥Æ¥à¤ÎÍÍ¡¹¤Êµ¡Ç½¤òSmarty¤ò»È¤Ã¤Æ¼ÂÁõ¤¹¤ë ·ÈÂÓ3¥¥ã¥ê¥¢Âбþ¤Î³¨Ê¸»úÂбþ¥µ¥¤¥È¤òSmarty¤Ç¹½ÃÛ¤¹¤ë²òÀâµ»ö
¥³¥á¥ó¥È
¥³¥á¥ó¥È¤Ï¼¡¤Î¤è¤¦¤Ëµ½Ò¤·¤Þ¤¹¡£
foo.tpl
{* ¤³¤ì¤ÏSmarty¤Î¥³¥á¥ó¥È¤Ç¤¹ *}
Æþ¤ì»Ò¤Ë¤Ï¤Ç¤¤Þ¤»¤ó¡£
Äê¿ô
¥Æ¥ó¥×¥ì¡¼¥È¤ÇÄê¿ô¤òÄêµÁ¤·¤Æɽ¼¨
ÀßÄê¥Õ¥¡¥¤¥ë¤Ë¤è¤ëÊÑ¿ôÄêµÁ
foo.conf
fax = '111-222-3333'
foo.tpl
{config_load file='foo.conf'} {#fax#}
PHP¤ÇÄê¿ô¤òÄêµÁ¤·¤Æɽ¼¨
foo.php
define('FAX','111-222-3333');
foo.tpl
{$smarty.const.FAX}
¢¨Í½ÌóÊÑ¿ô{$smarty}¤òÍøÍѤ·¤Þ¤¹¡£
ÊÑ¿ô
¥Æ¥ó¥×¥ì¡¼¥È¤ÇÊÑ¿ô¤òÄêµÁ¤·¤Æɽ¼¨
foo.tpl
{assign var=fax value='111-222-3333'} {$fax}
PHP¤ÇÊÑ¿ô¤òÄêµÁ¤·¤Æɽ¼¨
foo.php
$smarty = new Smarty(); $smarty->assign('fax', '111-222-3333');
foo.tpl
{$fax}
Ï¢ÁÛÇÛÎóÊÑ¿ô
PHP¤ÇÏ¢ÁÛÇÛÎóÊÑ¿ô¤òÄêµÁ¤·¤Æɽ¼¨
foo.php
$smarty = new Smarty(); $smarty->assign('foo', array('fax' => '111-222-3333', 'email' => 'zaphod@slartibartfast.example.com', 'phone' => array('home' => '111-222-3334', 'cell' => '111-222-3335') ) );
foo.tpl
{$foo.fax}
Ï¢ÁÛÇÛÎóÊÑ¿ô$foo['fax']¤òɽ¼¨ ¢¨Ï¢ÁÛÇÛÎó¤Ï¥Ô¥ê¥ª¥É¤ò»ÈÍѤ·¤Þ¤¹¡£ ¢¨Ä̾ï¤ÎÇÛÎó¤Ï{$foo[4]}¤È¤¤¤¦É÷¤Ë¤½¤Î¤Þ¤Þ¥Æ¥ó¥×¥ì¡¼¥È¤Ëµ½Ò¤·¤Þ¤¹
ͽÌóÊÑ¿ô{$smarty}
¥Ú¡¼¥¸Æɤ߹þ¤ß»þÅÀ¤ÇÍøÍѲÄǽ¤ÊͽÌóÊÑ¿ô{$smarty}
»ÈÍÑÎã | ÆâÍÆ | PHP¤Ç¤Îɽµ |
Smarty¤Î¥Ð¡¼¥¸¥ç¥ó¤Ï{$smarty.version}¤Ç¤¹¡£ | Smarty¤Î¥Ð¡¼¥¸¥ç¥ó | - |
¸½ºß¤Î¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë̾¤Ï{$smarty.template}¤Ç¤¹¡£ | ¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë̾ | - |
<a href="{$smarty.server.SCRIPT_NAME}?page=smarty">click me</a> | HTML¥Õ¥¡¥¤¥ë̾ | - |
Smarty¤Ç¤Î¥Ç¥ê¥ß¥¿¤Ï {$smarty.ldelim} ¤È {$smarty.rdelim} ¤Ç¤¹¡£ | Smarty¤Î¥Ç¥ê¥ß¥¿ | - |
{$smarty.get.foo} | get¥Ñ¥é¥á¡¼¥¿foo¤ÎÃÍ¡£ | $_GET['foo'] |
{$smarty.post.foo} | post¥Ñ¥é¥á¡¼¥¿foo¤ÎÃÍ¡£ | $_POST['foo'] |
{$smarty.cookies.foo} | ¥¯¥Ã¥¡¼ÊÑ¿ôfoo¤ÎÃÍ¡£ | $_COOKIE['foo'] |
{$smarty.server.HTTP_USER_AGENT} | ¥µ¡¼¥ÐÊÑ¿ôHTTP_USER_AGENT¤ÎÃÍ¡£ | $_SERVER['HTTP_USER_AGENT'] |
{$smarty.env.PATH} | ´Ä¶ÊÑ¿ôPATH¤ÎÃÍ¡£ | $_ENV['PATH'] |
{$smarty.session.foo} | ¥»¥Ã¥·¥ç¥óÊÑ¿ôfoo¤ÎÃÍ¡£ | $_SESSION['foo'] |
{$smarty.request.foo} | get, post, cookies, server, env¤É¤ì¤«¤Îfoo¤ÎÃÍ | - |
{$smarty.const.MY_CONST} | PHP¤Ç¼¡¤Î¤è¤¦¤ËÄêµÁ¤·¤¿ÃÍdefine('MY_CONST', 'abc'); | MY_CONST |
1970ǯ1·î1Æü¤«¤é¸½ºß¤Þ¤Ç¤Î·Ð²áÉÿô¤Ï{$smarty.now}ÉäǤ¹¡£ | 1970ǯ1·î1Æü¤«¤é¤Î·Ð²áÉÿô | - |
¸½ºß¤ÎÆü»þ¤Ï{$smarty.now|date_format:'%Y/%m/%d %H:%M:%S'}¤Ç¤¹¡£ | ¸½ºßÆü»þɽ¼¨ | - |
{foreach}¥ë¡¼¥×¤ÇÍøÍѲÄǽ¤ÊͽÌóÊÑ¿ô{$smarty}
»ÈÍÑÎã | ÆâÍÆ | ÃÍ |
{$smarty.foreach.loopname.iteration} | ¥ë¡¼¥×²ó¿ô | 1, 2, 3, ... |
{$smarty.foreach.loopname.index} | ¥¤¥ó¥Ç¥Ã¥¯¥¹ | 0, 1, 2, ... |
{if $smarty.foreach.loopname.first} | ºÇ½é¤Î¹àÌܤ«¤É¤¦¤«¿¿µ¶ÃÍ | true, false |
{elseif $smarty.foreach.loopname.last} | ºÇ¸å¤Î¹àÌܤ«¤É¤¦¤«¿¿µ¶ÃÍ | true, false |
{$smarty.foreach.loopname.total} | ¥ë¡¼¥×¤Î¥È¡¼¥¿¥ë²ó¿ô¡£¥ë¡¼¥×¤òÈ´¤±¤Æ¤âÍøÍѲÄǽ | ¿ôÃÍ |
{capture}¤ÇÍøÍѲÄǽ¤È¤Ê¤ëͽÌóÊÑ¿ô{$smarty}
{capture}¥¿¥°¤Ç°Ï¤Þ¤ì¤¿½ÐÎÏÆâÍƤòname°À¤Ç»ØÄꤷ¤¿ÊÑ¿ô¤Ë¼èÆÀ¤·¤Þ¤¹¡£
{capture}»ÈÍÑÎã
{* ¥³¥ó¥Æ¥ó¥Ä¤¬É½¼¨¤µ¤ì¤Ê¤¤¸Â¤ê¡¢¥Æ¡¼¥Ö¥ë¤Î¹Ô¤òɽ¼¨¤·¤Þ¤»¤ó *} {capture name=banner} {include file='get_banner.tpl'} {/capture} {if $smarty.capture.banner != ''} <div id="banner">{$smarty.capture.banner}</div> {/if}