$data['content'] = "用户不存在";
$data['url'] = array(
'0'=>array('text'=>'重新登录','href'=>Yii::$app->urlManager->createUrl('site/login')),);
return $this->renderPartial("showmsg", $data);
<div class="msg-box">
<div class="alert-box">
<h1 class="alert-title "><?= $content ?></h1>
<div class="alert-time"><span id="second">5</span>秒后自动跳转</div>
<div class="alert-url">
<?php
$i = 0;
foreach ($url as $k => $v) {
if($i == 0)
{
echo "<a id='firsta' href='".$v['href']."'>";
}else
{
echo "<a href='".$v['href']."'>";
}
echo $v['text']."</a>";
$i++;
}
?>
</div>
</div>
</div>
<script type="text/javascript">
function auto_redirect()
{
var redirect_url = document.getElementById("firsta").href;
var second = document.getElementById("second");
var totaltime=5;
var interval = setInterval(function(){
var time = --totaltime;
second.innerHTML=""+time;
if(time === 0) {
if(redirect_url!="")
{
window.location.href= redirect_url;
}else
{
window.history.back();
}
clearInterval(interval);
};
}, 1000);
}
window.onload = auto_redirect;
</script>