在codeigniter中调用模态表单视图

fdx2calv  于 2023-02-20  发布在  其他
关注(0)|答案(1)|浏览(73)

我有一个名为项目的视图,我想在其中使用此按钮在另一个视图中显示模态表单。

<a href="<?php echo base_url('items/Show/'.$value['id']); ?>" type="button" class="btn btn-secondary btn-sm edit btn-orange"   data-bs-toggle="modal" data-bs-target=".bs-example-modal-center"  title="View">
                                                <i class="fas fa-eye "></i>
                                            </a>

这是项目控制器中将数据加载到表单的函数

function Show($id){

        if (isset($id)){
            
            $this->load->model('Itemo');
            $data['view']=$this->Itemo->Edit_items($id);
            $this->load->view('user/Dashboard/header');
            $this->load->view('user/Dashboard/View',$data);
            $this->load->view('user/Dashboard/footer');

        }else{

            redirect('/items/List_cat', 'refresh');

        }

        }

这是一个视图,它包含了一个叫做View的模态表单

<div class="modal fade bs-example-modal-center" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
                                                <div class="modal-dialog modal-dialog-centered">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h5 class="modal-title">Center modal</h5>
                                                            <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                                aria-label="Close"></button>
                                                        </div>
                                                        <div class="modal-body">
                                                            <!-- /.data loaded here-->
                                                        </div>
                                                    </div>
                                                    <!-- /.modal-content -->
                                                </div>
                                                <!-- /.modal-dialog -->
                                            </div>
                                            <!-- /.modal -->
                                        </div>

但是当我点击按钮时什么也没显示

vhmi4jdf

vhmi4jdf1#

我认为要解决这个问题,可以更新button标签中的data-bs-target属性,使其与模态表单最外层div元素的ID匹配,即"modal-center"。
像这样:

<div class="modal fade" id="modal-center" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <!-- modal content here -->
</div>

和更改按钮

<a href="<?php echo base_url('items/Show/'.$value['id']); ?>" type="button" class="btn btn-secondary btn-sm edit btn-orange" data-bs-toggle="modal" data-bs-target="#modal-center" title="View">
  <i class="fas fa-eye "></i>
</a>

相关问题