天天看点

tp5 php里如何打印变量,TP5系统变量输出

1、系统变量

tp5 php里如何打印变量,TP5系统变量输出

在index.html文件中:

我是index控制器index操作模板文件

server.http_host: {$Think.server.http_host}

cookie.siteName: {$Think.cookie.siteName}

在index.php文件中:

namespace app\index\controller;

class Index extends \think\Controller

{

public function index()

{

setcookie('siteName','PHP中文网');

return $this -> fetch();

}

}

?>

此时浏览器会输出:

server.http_host: tp5.com

cookie.siteName:

注意,我们要刷新两遍,因为第一遍才会把cookie值写入,第二遍才能显示。

如果浏览器url为:tp5.com/index/index/index?id=250

我们的获取并显示get值,可以:

get: {$Think.get.id}

post值也同理。

系统常量CONF_PATH: {$Think.const.CONF_PATH}

浏览器会显示:系统常量CONF_PATH: /D:/phpStudy/PHPTutorial/WWW/tp5/public/../config

配置项database中的type值: {$Think.config.database['type']}

配置项database中的type值: {$Think.config.database.type}

总结:在模板中输出系统变量或常量,可以使模板的功能更加强大,完成更多的任务。