38

How to get URL using Smarty similar to window.location in JavaScript ?

I did this

{$smarty.server.PHP_SELF} 

but it's not working.

4

3 に答える 3

3

これはコントローラーコードです:

<?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>
于 2012-10-30T12:24:41.363 に答える