douren7179 2019-01-01 13:49
浏览 40

在codeigniter中将删除后的id发布

I have two tables users and posts where is the primary key is id. When i click on delete button, i want to post the id.

Here is my view:

<table class="table">
    <thead class="thead-dark">
        <tr>
            <th scope="col">Title</th><th scope="col">Hit</th>
            <th scope="col">Edit</th><th scope="col">Delete</th><th scope="col">Read More</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($posts as $post) : ?>
            <?php if($this->session->userdata('username') ==  $_SESSION["username"]): ?>
                <tr>
                    <td><?php echo $post['title']; ?> </td>
                    <td><?php echo $post['post_views']; ?></td>
                    <td><a class="btn btn-default" href="<?php echo base_url(); ?>posts/edit/<?php echo $post['slug']; ?>">Edit</a></td>
                    <td>
                        <?php echo form_open('/posts/delete/'.$post['id']); ?>
                            <input type="submit" value="Delete" class="btn btn-danger">
                            <input type="hidden" name="id" value="<?php echo $post['id'] ?>" />
                        </form>
                    </td>
                    <td><p><a class="btn btn-default" href="<?php echo site_url('/posts/'.$post['slug']); ?>">Read More</a></p></td>
                </tr>
            <?php endif; ?>
        <?php endforeach; ?>
    </tbody>
</table>
  • 写回答

3条回答 默认 最新

  • dongluan5740 2019-01-02 03:04
    关注

    There are so many ways to do this, the best most common one is to get it from the url like this:

    $id = @end($this->uri->segment_array());
    

    Or this:

    $id = $this->uri->segment(3);
    

    Or you can do this by passing it in a hidden input like this:

    <?php echo form_open('/posts/delete/'.$post['id']); ?>
        <input type="submit" value="Delete" class="btn btn-danger">
        <input type="hidden" name="id" value="<?php echo $post['id'] ?>" />
    </form>
    

    Or using ajax.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度