0

sensei. can you help me with my code? i wan to redirect page to the same page after edit it.

here is my controller

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')
}

suppose im editing the data from page number 3. how can i redirect to page 3 (app/book/3) again after submit the edited data?

i have try to solve it by get URI value(suppose the page is app/book/3)<-- i need this '3'to put in redirect code. so i implement this code from many stackeroverflow answer, hope to get some array i can use

$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);

but it results array()or null. anyone can help me. thanks

principiorum
  • 528
  • 7
  • 21

2 Answers2

-1

In the controller need to pass the last value like "3" as argument so that any edited value can be pass to the controller. And then after editing the code you can redirect by the php header function with the passed value as argument to redirect on the same page like this example:

<?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
    It is not really specified in the post itself, but the tags says codeigniter and the syntax looks like it is using functions of codeigniter. It also has a `redirect()` function. Why use `header()` instead? Also the full hardcoded URL is not needed. And why the `die()` there? – Fjarlaegur Sep 29 '17 at 09:38
  • Ok for the codigniter, need to use redirect function where need to pass id on the routing of the URL. – Syed Imran Ertaza Sep 29 '17 at 11:53
-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;

    }

try below code me be solve u r issue. i have pass id in url.

  • 1
    `$id` is not pagination id. Read question again. First understand it then give answer. Don't just dump answer without any effort. – B. Desai Sep 29 '17 at 10:49