php Codeigniter - Bootstrap Modal - 传递数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13708010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:55:45  来源:igfitidea点击:

Codeigniter - Bootstrap Modal - passing data

phpcodeignitertwitter-bootstrap

提问by SuperNinja

I am pretty new to Codeigniter and aiming to follow best practice as I learn. Currently I have a table that is generated via DB

我对 Codeigniter 还很陌生,我的目标是在学习时遵循最佳实践。目前我有一个通过 DB 生成的表

HTML Table

HTML表格

<tr>
    <td>
      <a class="galName" href="#myModal" data-toggle="modal" >
        <?php echo $gal['name']; ?>
      </a>
    </td>
    <td>
      <?php echo $gal['clientName']; ?>
    </td>
</tr>
<?php endforeach; ?>

The Modal

模态

<div class="modal fade hide modal-creator" id="myModal" style="display: none;" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3>Edit Gallery</h3>
    </div>
    <div class="modal-body"><?php echo form_open('url'); ?>

    <div class="row">
        <div class="span5">
            <?php print_r($galleryName); ?>
            <div class="control-group">
                <?php
                    $galleryName = array(
                        'id'            => 'galleryName',
                        'name'          => 'galleryName',
                        'placeholder'   => 'Gallery Name',
                        'required'      => 'required',
                    );
                    echo form_label('Gallery Name:', 'galleryName');
                    echo form_input($galleryName);
                ?>
            </div><!-- /control-group -->
       </div><!--/span5-->
   </div><!--/row-->
</div><!-- /modal-body -->

<div class="modal-footer">
    <!-- <p class="span3 resize">The following images are sized incorrectly. Click to edit</p> -->
    <a href="javascript:;" class="btn" data-dismiss="modal">Close</a>
    <a href="javascript:;" class="btn btn-primary">Next</a>
</div>

The link calls a bootstrap modal where I want to pass the data for the selected gallery. I know that I can pass the data via jQuery, but is it possible to keep this modal in the MVC framework and if yes how does one go about calling the controller via the modal link?

该链接调用引导模式,我想在其中传递所选图库的数据。我知道我可以通过 jQuery 传递数据,但是是否可以在 MVC 框架中保留这种模式,如果是的话,如何通过模式链接调用控制器?

Thanks so much on the help, and would be happy to accept any suggestions on resources for CodeIgniter. I am currently working through the Nettuts videos, though they are dated,and also working through the user guide.

非常感谢您的帮助,并且很乐意接受有关 CodeIgniter 资源的任何建议。我目前正在浏览 Nettuts 视频,尽管它们已经过时了,并且还在浏览用户指南。

采纳答案by itsme

i really think you are misunderstanding what modal is and what a controller is, you can't do this without ajax call: how does one go about calling the controller via the modal link

我真的认为您误解了模态是什么以及控制器是什么,如果没有 ajax 调用,您就无法做到这一点: how does one go about calling the controller via the modal link

what i usually do is to create a view/modals/folder then put there all my bootstrap modals so for example:

我通常做的是创建一个view/modals/文件夹,然后把我所有的引导模式放在那里,例如:

application/views/modals/my_modal_form.php

and that will looks as you shown, inside:

这将如您所示,在里面:

<div class="modal fade hide modal-creator" id="myModal" style="display: none;" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3>Edit Gallery</h3>
    </div>
    <div class="modal-body"><?php echo form_open('url'); ?>

    <div class="row">
        <div class="span5">
            <?php print_r($galleryName); ?>
            <div class="control-group">
                <?php
                    $galleryName = array(
                        'id'            => 'galleryName',
                        'name'          => 'galleryName',
                        'placeholder'   => 'Gallery Name',
                        'required'      => 'required',
                    );
                    echo form_label('Gallery Name:', 'galleryName');
                    echo form_input($galleryName);
                ?>
            </div><!-- /control-group -->
       </div><!--/span5-->
   </div><!--/row-->
</div><!-- /modal-body -->

<div class="modal-footer">
    <!-- <p class="span3 resize">The following images are sized incorrectly. Click to edit</p> -->
    <a href="javascript:;" class="btn" data-dismiss="modal">Close</a>
    <a href="javascript:;" class="btn btn-primary">Next</a>
</div>

so when i need that single modal i just load it inside the main controller view i want to show up that modal doing simply:

所以当我需要那个单模态时,我只是将它加载到主控制器视图中,我想简单地显示该模态:

    <body>
    <?php echo $this->load->view('modals/my_modal_form'); ?>

    <tr>
    <td>
      <a class="galName" href="#myModal" data-toggle="modal" >
        <?php echo $gal['name']; ?>
      </a>
    </td>
    <td>
      <?php echo $gal['clientName']; ?>
    </td>
</tr>
<?php endforeach; ?>
    </body>

回答by Donald P. Morton

Ajax is the way to go, i made a template library in wich i load all my modals so they can be called by javscript from anywhere on the app, then use ajax to submit the forms

Ajax 是要走的路,我制作了一个模板库,我加载了所有的模态,这样它们就可以从应用程序的任何地方通过 javscript 调用,然后使用 ajax 提交表单