如何使用smarty获取网址(类似于JavaScript中的window.location
)?如何使用smarty获取当前网址
我这样做
{$smarty.server.PHP_SELF}
,但它不工作。给我一个解决方案。
如何使用smarty获取网址(类似于JavaScript中的window.location
)?如何使用smarty获取当前网址
我这样做
{$smarty.server.PHP_SELF}
,但它不工作。给我一个解决方案。
你可以用这个。
{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}
这应该是最好的答案! – shawndreck
我同意。它快速而坚实。 – cptnk
如果用户篡改头字段,这可能会导致一些安全问题:http://stackoverflow.com/questions/6768793/get-the-full-url-in-php –
这是控制器代码:
<?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>
你得到了什么输出? – senthilbp
控制器,我得到了 – Athi