2017-09-29 62 views
0

sensei。你能幫我用我的代碼嗎?我想在編輯之後將頁面重定向到同一頁面。如何在編輯數據後重定向到同一頁面?

這裏是我的控制器

function edit_book(){ 
$editBook = array(
    'id' => $this->input->post('id'), 
    'book_title' => $this->input->post('book_title'), 
    'category' => $this->input->post('category'), 
    'author' => $this->input->post('author') 
    ): 
    $this->m_profile->edit_book($data1, $data, 'book_data'); 
    redirect('app/book') 
} 

假設IM編輯從頁碼3.數據我如何可以重定向到第3頁(應用程序/電子書/ 3)後再次提交編輯的數據?

我試圖通過獲取URI值來解決它(假設頁面是app/book/3)< - 我需要這個'3'來放置重定向代碼。所以我從許多stackeroverflow答案實現這個代碼,希望能得到一些陣列,我可以使用

$url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; 
$escaped_url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); 
$query_str = parse_url($escaped_url, PHP_URL_QUERY); 
parse_str($query_str, $query_params); 
print_r($query_params); 

,但它會導致陣列()或空。任何人都可以幫助我。謝謝

+0

可能重複[如何重定向到PHP中的同一頁](https://stackoverflow.com/questions/8130990/how-to-redirect-to-the-same-page-in-php) –

+0

有你試過'$ _SERVER ['HTTP_REFERER']'? – Cashbee

+0

你可以使用'$ config ['uri_segment']''在CI –

回答

-1

在控制器中需要傳遞最後一個值,如「3」作爲參數,以便可以將任何編輯的值傳遞給控制器​​。然後編輯代碼後,你可以通過傳遞的值作爲參數的PHP頭功能重定向到同一頁面上的重定向這樣的例子:

<?php  
function edit_book($id){ 

Your all edited codes here. 

// To redirect to the same page with avalue 
redirect('same_controller/method/'.$id, 'refresh'); 
} 
?> 
+1

它在帖子本身並沒有真正指定,但標籤說codeigniter和語法看起來像它使用codeigniter函數。它也有一個'redirect()'函數。爲什麼使用'header()'而不是?此外,完整的硬編碼URL不是必需的。以及爲什麼'死()'在那裏? – Clemenz

+0

好的codigniter,需要使用重定向功能,如果需要在URL的路由上傳遞id。 – Webdeveloper011

-1
function edit_book(){ 
     $id = $this->input->post('id'); 
    $editBook = array(
     'id' => $this->input->post('id'), 
     'book_title' => $this->input->post('book_title'), 
     'category' => $this->input->post('category'), 
     'author' => $this->input->post('author') 
     ): 
     $this->m_profile->edit_book($data1, $data, 'book_data'); 
     $url = base_url('app/book/'.$id); 
     redirect($url) 
    } 

    function book($id = NULL) 
    { 
     //get record using $id; 

    } 

試試下面的代碼我可以解決ü[R問題。我在URL中傳遞了id。

+1

'$ id'不是分頁ID。再次閱讀問題。先了解它然後給出答案。不要在沒有任何努力的情況下丟棄答案。 –

相關問題