【发布时间】:2012-10-19 18:40:38
【问题描述】:
如何使用类似于JavaScript 中的window.location 的Smarty 获得URL?
我做了这个
{$smarty.server.PHP_SELF}
但它不起作用。
【问题讨论】:
标签: smarty
如何使用类似于JavaScript 中的window.location 的Smarty 获得URL?
我做了这个
{$smarty.server.PHP_SELF}
但它不起作用。
【问题讨论】:
标签: smarty
你也可以用这个。
{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}
【讨论】:
这是控制器代码:
<?php
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pro = 'https';
} else {
$pro = 'http';
}
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
$current_url = $pro."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
$smarty->assign("current_url",$current_url);
$smarty->display('index.tpl');
?>
您可以在 index.tpl 模板文件中显示变量:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Title</title>
</head>
<body>
{$current_url}
</body>
</html>
【讨论】:
看看有什么可用的:
{$smarty.server|@var_dump}
几个网址示例https://some.example.com/some/path?param=1:
{$smarty.server.SCRIPT_URI}
https://some.example.com/some/path
{$smarty.server.SERVER_NAME}
some.example.com
{$smarty.server.SCRIPT_URL}
/一些/路径
【讨论】: