PHP中 超全域數組與Smarty中對應的請求變數

來源:互聯網
上載者:User

$_GET     <{$smarty.get}>

$_POST    <{$smarty.post}>

$_COOKIE   <{$smarty.cookie}>

$_SESSION     <{$smarty.session}>

$_FILES   無(因為前台用不到)

$_SERVER    <{$smarty.server}>

$_REQUEST    <{$smarty.request}>

$_ENV    <{$smarty.env}>

$GLOBALS 無

 

使用Smarty模板引擎中的請求變數,就可以直接請求資料,而不必從php接收再分配了

例子:

 代碼如下 複製代碼

<{$smarty.get}>

 

PHP方式:$tpl->assign("id",$_GET['id']);

<{$id}>

Smarty請求變數方式:<{$smarty.get.id}>

2. <{$smarty.session}>

PHP方式:$_SESSION['name']="MarcoFly";

 代碼如下 複製代碼

$tpl->assign("name",$_SESSION['name']); 

<{$name}>//

輸出到模板

Smarty請求變數方式:

 代碼如下 複製代碼

<{$smarty.session.name}>

Smarty模板引擎中的保留變數<{$smarty}>:

<{$smarty.const}>可以通過“.”方式訪問任意一個常量(包括自訂和系統常量)

例子:

 代碼如下 複製代碼

<{$smarty.const.__FILE__}>

define(“PI”,3.1415926); //定義PHP常量

<{$smarty.const.PI}> //利用smarty輸出常量PI

Smarty訪問設定檔的兩種方式

 代碼如下 複製代碼

方式一:<{##}>

方式二:<{$smarty.config}> //保留變數的形式

擷取當前伺服器的時間:

不需要使用php從伺服器取得時間,只需簡單的使用smarty的保留變數來取得

 代碼如下 複製代碼

<{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.