PHP头条
热点:

PHP Smarty 保留变量,phpsmarty保留变量


无需在php中分配,直接可以在模板页面中使用的变量。包括php中的超级全局变量,比如$_GET,$_SERVER,还有smarty自带的一些变量。
使用格式:{$smarty.保留变量名}

hold.php(后端):

<?php
include "libs/Smarty.class.php";
$smarty = new Smarty();
$smarty->template_dir = "templates";
$smarty->compile_dir = "templates_c";

//定义一个常量(声明常量的值)
define("ROOT", getcwd());    //getcwd() 获取当前物理路径。
$smarty->display("hold.tpl");
hold.tpl(前端视图):
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<h2>保留变量</h2>      {* 保留变量不需在php中定义,可以直接在模板文件中使用。 *}
	<p>{$smarty.server.SERVER_NAME}</p>  {* 超全局标量。 $smarty.post.userName *}
	<p>{$smarty.now}</p>     {* Smarty自带的变量,返回时间戳 *}
	<p>{$smarty.version}</p>
	
	{* 对于常量而言,一定要先在php中定义(声明它的值),但无需分配 *}
	<p>{$smarty.const.ROOT}</p>
</body>
</html>


www.phpzy.comtrue/php/5768.htmlTechArticlePHP Smarty 保留变量,phpsmarty保留变量 无需在php中分配,直接可以在模板页面中使用的变量。包括php中的超级全局变量,比如$_GET,$_SERVER,还有smarty自带的一些变量。 使用格式:{$smart...

相关文章

相关频道:

PHP之友评论

今天推荐