保留变量
{$smarty} 保留變量
可以通過(guò)PHP的保留變量?{$smarty}來(lái)訪問(wèn)一些環(huán)境變量。 下面是這些變量的列表:
頁(yè)面請(qǐng)求變量
頁(yè)面請(qǐng)求變量如$_GET,?$_POST,?$_COOKIE,?$_SERVER,?$_ENV?和?$_SESSION?可以通過(guò)下面的方式來(lái)使用:
Example?4.8.?顯示頁(yè)面請(qǐng)求變量
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page}{* display the variable "page" from a form ($_POST['page']) *}
{$smarty.post.page}{* display the value of the cookie "username" ($_COOKIE['username']) *}
{$smarty.cookies.username}{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}{* display the system environment variable "PATH" *}
{$smarty.env.PATH}{* display the php session variable "id" ($_SESSION['id']) *}
{$smarty.session.id}{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username} {$smarty.now}
當(dāng)前的時(shí)間戳?可以通過(guò){$smarty.now}來(lái)獲取。 時(shí)間戳是從1970年1月1日開(kāi)始計(jì)算到當(dāng)前的秒數(shù)。 當(dāng)前時(shí)間戳可以被date_format?修飾器使用并顯示。 注意:在每次使用該變量時(shí)都會(huì)調(diào)用time()函數(shù)。 比如說(shuō)一個(gè)程序花了三秒來(lái)執(zhí)行,在開(kāi)頭和結(jié)束時(shí)都調(diào)用了$smarty.now,那么這兩個(gè)數(shù)值將差三秒。
{* use the date_format modifier to show current date and time *}
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'} {$smarty.const}
直接訪問(wèn)PHP的常量。參見(jiàn)?smarty 常量.
<?php
// the constant defined in php
define('MY_CONST_VAL','CHERRIES');
?> 在模板中顯示常量
{$smarty.const.MY_CONST_VAL} {$smarty.capture}
Smarty內(nèi)置函數(shù)?{capture}..{/capture}可以捕獲其中的代碼輸出。 通過(guò){$smarty.capture}變量可以使用這些輸出的代碼。 參見(jiàn)?{capture}函數(shù)。
{$smarty.config}
{$smarty.config}變量可以獲取?配置變量。?{$smarty.config.foo}可獲取設(shè)置變量的{#foo#}。參見(jiàn)?{config_load}。
{$smarty.section}
{$smarty.section}變量是{section}?循環(huán)中的屬性。 它提供了一些很有用的值,如.first,?.index等等。
{$smarty.template}
返回當(dāng)前的模板名稱(不帶目錄名)。
{$smarty.template_object}
返回當(dāng)前模板對(duì)象。
{$smarty.current_dir}
返回當(dāng)前模板的目錄名稱。
{$smarty.version}
<div id="footer">由 Smarty {$smarty.version} 引擎驅(qū)動(dòng)</div> 返回編譯當(dāng)前模板的Smarty版本。
{$smarty.block.child}
返回子模板提供的區(qū)塊代碼。 參見(jiàn)模板繼承。
{$smarty.block.parent}
返回父模板提供的區(qū)塊代碼。 參見(jiàn)模板繼承。
{$smarty.ldelim}, {$smarty.rdelim}
用于顯示左定界符和右定界符。等同于?{ldelim},{rdelim}。
參見(jiàn)?賦值變量?和?配置變量
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/gaocy/p/8167186.html
總結(jié)
- 上一篇: 盆腔炎导致输卵管不通
- 下一篇: 爆竹声中一岁除下一句是什么呢?