我对Codeigniter很陌生,并希望在我学习的时候遵循最佳实践。目前我有一个通过DB
生成的表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; ?>
模态
<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>
链接调用bootstrap模式,我想在其中传递所选库的数据。我知道我可以通过jQuery传递数据,但是可以将这个模态保存在MVC框架中,如果是的话,如何通过模态链接调用控制器?
非常感谢您的帮助,并乐意接受有关CodeIgniter资源的任何建议。我目前正在研究Nettuts视频,虽然它们已经过时,但也在使用用户指南。
答案 0 :(得分:4)
我真的认为你误解了模态是什么以及控制器是什么,如果没有ajax调用你就不能这样做:how does one go about calling the controller via the modal link
我通常做的是创建一个view/modals/
文件夹,然后将所有我的引导模态放在那里,例如:
application/views/modals/my_modal_form.php
并且看起来就像你在里面看到的那样:
<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>
因此,当我需要单个模态时,我只需将其加载到主控制器视图中,我想简单地显示该模态:
<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>
答案 1 :(得分:0)
Ajax是要走的路,我创建了一个模板库,我加载了所有的鼹鼠,这样就可以通过javascript从应用程序的任何地方调用它们,然后使用ajax提交表单