tp5.1前台模板的系统变量输出

系统变量输出

普通的模板变量需要首先赋值后才能在模板中输出,但是系统变量则不需要,可以直接在模板中输出,系统变量的输出通常以{$Think.(大小写一致) 打头,例如:

{$Think.server.script_name} // 输出$_SERVER['SCRIPT_NAME']变量
{$Think.session.user_id} // 输出$_SESSION['user_id']变量
{$Think.get.page} // 输出$_GET['page']变量
{$Think.cookie.name}  // 输出$_COOKIE['name']变量

支持输出 $_SERVER$_ENV、 $_POST、 $_GET、 $_REQUEST$_SESSION和 $_COOKIE变量。

常量输出

还可以输出常量

{$Think.const.PHP_VERSION}

或者直接使用

{$Think.PHP_VERSION}

配置输出

输出配置参数使用:

{$Think.config.default_module}
{$Think.config.default_controller}

语言变量

输出语言变量可以使用:

{$Think.lang.page_error}
{$Think.lang.var_error}

请求变量

模板支持直接输出Request请求对象的方法参数,用法如下:

$Request.方法名.参数

例如:

{$Request.get.id}
{$Request.param.name}

$Request.开头的变量输出会认为是系统请求对象的参数输出。

支持Request类的大部分方法,但只支持方法的第一个参数。

下面都是有效的输出:

// 调用Request对象的get方法 传入参数为id
{$Request.get.id}
// 调用Request对象的param方法 传入参数为name
{$Request.param.name}
// 调用Request对象的param方法 传入参数为user.nickname
{$Request.param.user.nickname}
// 调用Request对象的root方法
{$Request.root}
// 调用Request对象的root方法,并且传入参数true
{$Request.root.true}
// 调用Request对象的path方法
{$Request.path}
// 调用Request对象的module方法
{$Request.module}
// 调用Request对象的controller方法
{$Request.controller}
// 调用Request对象的action方法
{$Request.action}
// 调用Request对象的ext方法
{$Request.ext}
// 调用Request对象的host方法
{$Request.host}
// 调用Request对象的ip方法
{$Request.ip}
// 调用Request对象的header方法
{$Request.header.accept-encoding}
 
原文地址:https://www.cnblogs.com/yinyusoso/p/9117192.html