【发布时间】:2017-11-25 10:47:22
【问题描述】:
如何在 CodeIgniter 中使用 redirect() 打开 Bootstrap 模式? 要么 如何在模型的视图中执行具有特定 id 的特定 div?
我正在尝试在同一页面中成功提交表单时打开 Bootstrap 模式。
【问题讨论】:
标签: codeigniter
如何在 CodeIgniter 中使用 redirect() 打开 Bootstrap 模式? 要么 如何在模型的视图中执行具有特定 id 的特定 div?
我正在尝试在同一页面中成功提交表单时打开 Bootstrap 模式。
【问题讨论】:
标签: codeigniter
根据question的这个答案:
Step 1) 将 Modal 的 HTML 放入一个视图文件中(在控制器完成处理后显示)。
步骤2)从控制器中放入一些flash数据,以满足是否显示弹出窗口的条件。
步骤 3) 在视图中检查 flash 会话数据是否已设置。 我已经提供了控制器和视图文件的代码。
编辑 如果你想重定向到同一个页面,那么你必须在 ajax 的帮助下完成所有的处理:
$.ajax({
type: 'POST',
url: "url/to/your/controller/function",
success: function(response){
if(response == "Success"){
$('#thankyouModal').modal('show');
}else{
alert("Something just went wrong, Please try again later...");
}
},
error: function(){
alert("Something just went wrong, Please try again later...");
}
});
【讨论】:
Pass the value for success variable from controller
<script type="text/javascript">
<?php if( $success == TRUE ){
?>
$('#myModal').modal('show');
<?php
}
?>
</script>
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<a href="#" class="btn">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div>
【讨论】:
您可以通过以下方式设置flash数据
public function insert($data) {
// Inserting into your table
// Calling model
$done = $this->db->insert('sign_up', $data);
// You can do something else here
if($done) {
//You can set the message and variable name as per your need.
$this->session->set_flashdata('inserted','Yes');
//Redirect to the desired view file
redirect("controller/anotherfunction_where_view_file_is_loaded");
}
注意“$this->session->set_flashdata('inserted','Yes');”这一行
在这一行中,您可以设置闪存数据,其中第一个参数将是键,第二个参数将是它的值,因此如果您打印会话变量,您将创建一个具有相同名称的键值对。 请注意,刷新页面后数据将被删除。
【讨论】: