2011-08-01 15 views
-1

我有一個我想加載並顯示一段時間的頁面。然後應該將用戶重定向回索引視圖。如何使用PHP和codeigniter在一段時間後重定向用戶?

下面的代碼是我的控制器。

function send() 
{ 
    $data = array(
     'author' => $_POST['author'], 
     'header' => $_POST['header'], 
     'paragraph' => $_POST['paragraph'] 
    ); 

    $result = $this->database_model->insert_into_articles($data); 

    if($result) 
    { 

     $view['content'] = "articles_send_view"; 
      $this->load->view('includes/template',$view); 

    } 

} 

以下是我的看法。

<div id="content"> 
<div id='other_content'> 
<p> 
    article sent thanks 
</p> 

</div> 

+2

我不明白問什麼。你是否要求頁面加載被延遲?你問如何重定向? – Nightfirecat

+0

你需要看看阿賈克斯呼籲 – Sparkup

回答

4

我不相信這可以用PHP單獨完成。您在HTML中有兩個選項。

A <meta http-equiv="refresh">您的<head>中的標記可用於在指定的秒數後重新加載或重定向用戶。 Wikipedia has a couple of examples:5秒後

<meta http-equiv="refresh" content="5"> 

重定向到http://example.com/

廣場內<head>在5秒鐘後刷新頁面

<meta http-equiv="refresh" content="5; url=http://example.com/"> 

重定向到http://example.com/立刻道:

<meta http-equiv="refresh" content="0; url=http://example.com/"> 

另一種選擇是使用JavaScript重定向用戶。您可以通過修改the window.location property,使用the setTimeout function來延遲呼叫,例如5秒(5000毫秒)來完成此操作。

var redirect = function() { 
    window.location = "/index.html"; 
}; 

setTimeout(redirect, 5000); 

<meta>重定向應適用於幾乎所有的觀衆,而他們是否禁用了JavaScript,JavaScript的將無法正常工作。但是,這些內容不會以任何方式發生衝突,因此您可以在網頁上同時包含這兩項內容以確保安全。

+0

好的謝謝你的幫助 – osos

相關問題