Come ottenere url utilizzando smarty (simile a window.location
in JavaScript)?Come ottengo l'URL corrente usando smarty
ho fatto questo
{$smarty.server.PHP_SELF}
ma non il suo lavoro. Dammi una soluzione.
Come ottenere url utilizzando smarty (simile a window.location
in JavaScript)?Come ottengo l'URL corrente usando smarty
ho fatto questo
{$smarty.server.PHP_SELF}
ma non il suo lavoro. Dammi una soluzione.
È possibile utilizzare questo, anche.
{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}
Questa dovrebbe essere la migliore risposta! – shawndreck
Sono d'accordo. È veloce e solido. – cptnk
Ciò potrebbe causare alcuni problemi di sicurezza se l'utente altera i campi dell'intestazione: http://stackoverflow.com/questions/6768793/get-the-full-url-in-php –
Questo è il codice di controllo:
<?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');
?>
È possibile visualizzare variabile nel file di modello 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>
Quale output hai? – senthilbp
controller questo ho ottenuto – Athi