简体   繁体   English

Codeigniter:将数据从视图传递到控制器

[英]Codeigniter: passing data from view to controller

This is my view code: 这是我的查看代码:

<p align="center"; style="font-size:22px">Database books</p>
        <table>
      <tr>
        <th>Book ID</th>
        <th>Book Name</th>
        <th>Description</th>
        <th>Author</th>
        <th>Publisher</th>
        <th>Pages</th>
        <th>Publication Date</th>
        <th>Price</th>
        <th>Status</th>
        <th>Quantity</th>
        <th>Genres</th>
        <th>User Rating</th>
        <th>Reviews</th>
        <th>Edit</th>
      </tr>
      <?php foreach($books as $book) { ?>
      <tr>
        <td><?php echo $book->book_id ?></td>
        <td><?php echo $book->book_name ?></td>
        <td><?php echo $book->description ?></td>
        <td><?php echo $book->author ?></td>
        <td><?php echo $book->publisher ?></td>
        <td><?php echo $book->pages ?></td>
        <td><?php echo $book->publication_date ?></td>
        <td><?php echo $book->price ?></td>
        <td><?php echo $book->status ?></td>
        <td><?php echo $book->quantity ?></td>
        <td><?php echo $book->genres ?></td>
        <td><?php echo $book->user_rating ?></td>
        <td><?php echo $book->reviews ?></td>
        <td><a href="<?php echo base_url(); ?>admin/edit_data">Edit</a></td>
      </tr>
      <?php } ?>
    </table>

May i know how do i pass data from my view to my controller, as i would like to pass the information to my edit page. 我想知道如何将数据从视图传递到控制器,因为我想将信息传递到编辑页面。 I am trying to search on passing variable using anchor tag, however i am getting information on using GET and POST only are there any other ways? 我正在尝试使用锚标记搜索传递的变量,但是我正在获取有关使用GET和POST的信息,还有其他方法吗?

Change the href link to 将href链接更改为

href="<?php echo base_url(); ?>admin/edit_data/<?php echo $book->book_id ?>"

Then you can get the book id on your controller function edit data 然后,您可以在控制器功能编辑数据上获取书号

function edit_data($bookid) {

    //you can use $bookid to fetch data from db

}

The above href link is right. 上面的href链接是正确的。

href="<?php echo base_url(); ?>admin/edit_data/<?php echo $book->book_id ?>"

just add $bookid = $this->uri->segment(3); 只需添加$bookid = $this->uri->segment(3); inside function edit_data() {// do stuff here} to retrieve book id from the href link. 内部function edit_data() {// do stuff here}以从href链接中检索书籍ID。

function edit_data() {
   $bookid = $this->uri->segment(3);
    //retrieving book id
}

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

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