在CodeIgniter中使用redirect()的引导模式
如何在CodeIgniter中使用redirect()打开引导模式? 或 如何在模型视图中使用特定id执行特定div 我试图在同一页面中成功提交表单时打开引导模式。在CodeIgniter中使用redirect()的引导模式,codeigniter,Codeigniter,如何在CodeIgniter中使用redirect()打开引导模式? 或 如何在模型视图中使用特定id执行特定div 我试图在同一页面中成功提交表单时打开引导模式。从控制器传递成功变量的值 Pass the value for success variable from controller <script type="text/javascript"> <?php if( $success == TRUE ){ ?> $('#myModal').modal('s
从控制器传递成功变量的值
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>
$('myModal').modal('show');
根据此答案:
步骤1)将Modal的HTML放入视图文件中(在控制器完成处理后显示)
步骤2)从控制器中放入一些闪存数据,以便您能够满足显示或不显示弹出窗口的条件
步骤3)查看是否设置了闪存会话数据。
我已经提供了控制器和视图文件的代码
编辑
如果要重定向到同一页面,则必须借助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...");
}
});
您可以按以下方式设置闪存数据
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')
在这一行中,您可以设置闪存数据,其中第一个参数将是键,第二个参数将是其值,因此,如果打印会话变量,您将创建一个具有相同名称的键值对。
请注意,刷新页面后,数据将被删除。如何执行步骤2我正在为步骤2提供新答案,但我可以在哪里放置模态id或执行与模态相关的操作?我对会话不太熟悉。您可以将模态id(或显示/调用模态)放在视图文件中。请阅读这篇文章中我的答案