简体   繁体   English

如何将数据从视图文件传递到控制器?

[英]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 ..?我正在使用 codeigniter-3 框架来开发 Web 应用程序,当我单击任何特定记录时,我有一个更新表单,它会获取该特定记录的 ID 并传递给 URL,这部分工作正常,现在我想要而不是使用id 我想获取所有记录数据并传递给控制器​​而不是 url 参数你能给我一些想法如何做到这一点..?

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.像这样,我正在获取特定坦克的 id,但现在我想要该特定记录的整个对象或数组并传递给控制器​​而不是 URL 参数。

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

controller.php控制器.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.在您的视图中,在 url 段中设置 id。

 <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.在您的控制器中,接收 uri 类通过链接传递的值。

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是的,有一种方法可以通过 session 而不是 url 设置 id,设置 user_id 可以这样做

$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有关如何使用会话的更多详细信息,您可以转到此 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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