简体   繁体   中英

How to pass data from view file to the controller?

I am using codeigniter-3 framework for developing web application, i have one update form when ever i click on any particular record it's taking an ID of that particular record and passing to the URL this part is working fine,now i want instead of taking id i want to take all the record data and passed to the controller instead of the url parameters can you give me some idea how to do this one ..?

like this i am taking the id of particular tank but now i want entire object or array of that particular record and passing to the controller instead of the URL parameters.

    <a class="dropdown-item" href="<?php echo base_url(); ?>book/edit_book?book_id=<?php echo $book['book_id']; ?>">Update</a>

controller.php

    $book_id = $this->input->get('book_id',TRUE);
        $url = 'http://local.com/books?book_id='.$book_id;
//rest of my logic based on the URL

In your view set id in url segment.

 <a class="dropdown-item" href="<?php echo base_url(); ?>book/edit_book/<?php echo $book['book_id']; ?>">Update</a>

In your controller ,receive the value passed through link by uri class.

Controller :

  $book_id = $this->uri->segment(3);
  $url = 'http://local.com/books?book_id='.$book_id;

Yes, there is a way to set id via session instead of url, to set user_id can do it like this

$this->session->set_userdata('book_id', $book_id);

Then you can retrive data session like this

$this->session->userdata('book_id')

For more detail how to use session you can go to this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM