Php Codeigniter-在模式窗口中显示信息
我有一个模态窗口。它与javascript配合得很好。我自己尝试了一些东西,但我无法在模式窗口中显示任何客户信息。单击“信息”按钮时,我想显示客户的信息。如何在模式窗口中显示任何客户信息 控制器:Php Codeigniter-在模式窗口中显示信息,php,ajax,codeigniter,model,modal-dialog,Php,Ajax,Codeigniter,Model,Modal Dialog,我有一个模态窗口。它与javascript配合得很好。我自己尝试了一些东西,但我无法在模式窗口中显示任何客户信息。单击“信息”按钮时,我想显示客户的信息。如何在模式窗口中显示任何客户信息 控制器: public function index() { $viewData['countries'] = $this->db->get("country")->row(); $viewData['customers'] = $this->customer_mode
public function index()
{
$viewData['countries'] = $this->db->get("country")->row();
$viewData['customers'] = $this->customer_model->get_all();
$this->lang->load('content', $this->session->userdata('people_lang'));
$this->load->view('customers', $viewData);
}
public function getInfo(){
$cusId = $this->input->post('cusId');
$viewData['customers'] = $this->db->where("cusId", $cusId)->get("customer")->row();
$this->load->view('customers/getInfo', $viewData);
}
此Ajax代码:
<script type="text/javascript">
function showCustomers(str){
$.ajax({
type: "POST",
data: { cusId: str },
url: "<?=base_url('customers/getInfo');?>",
success: function(data) {
$('#divInfo').html(data);
}
});
}
</script>
功能展示客户(str){
$.ajax({
类型:“POST”,
数据:{cusId:str},
url:“”,
成功:功能(数据){
$('#divInfo').html(数据);
}
});
}
这种模式:
<!-- Modal -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal Tittle</h4>
</div>
<div class="modal-body">
<div id="divInfo"></div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
<button class="btn btn-warning" type="button"> Confirm</button>
</div>
</div>
</div>
</div>
<!-- modal -->
&时代;
情态标题
接近
证实
这一观点:
<a data-toggle="modal" href="#myModal3"><button class="btn btn-primary btn-xs" onclick="showCustomers(this.id);" id="<?php echo $customers->cusId; ?>"><i class="fa fa-eye"></i></button>
以下是一种方法:
<!--modify button to include an onclick element, pass a value to it-->
<button class="btn btn-primary btn-xs" id="info_modal" onclick="show_modal('<?=$customer_name;?>')"><i class="fa fa-eye"></i></button>
我想你可以通过增加几行来做到这一点
注意*代码未经测试,我几乎可以画出解决此问题的想法。
在控制器的索引功能中
public function index(){
$viewData['countries'] = $this->db->get("country")->row();
$viewData['customers'] = $this->customer_model->get_all();
//**new line
// Assuming you already have method in your Model to get customer by id
// Check if there's a GET request of 'customerID' then assign to the $viewDataByID array the data from the model, else nothing.
$viewDataByID['customersById'] = (isset($_GET['cusomterID'])) ? $this->customer_model->get_by_id($id) : '';
//Then you'll have to update the variable sent to the view by storing both in one array
$allData['viewData']= $viewData;
$allData['viewDataByID'] = $viewDataByID;
$this->lang->load('content', $this->session->userdata('people_lang'));
$this->load->view('customers', $allData);// $allData get sent to the view
}
在您的模式中,您可以发送请求
请更新视图中的变量。您可以执行print_r($allData)或var_dump($allData)以清楚地看到数据树以及如何使用它们
或者,如果您不想为此使用索引,您可以在控制器中创建另一个函数,通过id、json_编码结果,然后使用jQuery获取数据
希望这有帮助。我回答了自己这个问题
<td data-title="Edit" align="center"><a href="<?php echo base_url("customer_edit/edit/$customer->cusId"); ?>"><button class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></button></a> <a data-toggle="modal" href="#<?php echo $customer->cusId; ?>"><button class="btn btn-primary btn-xs"><i class="fa fa-eye"></i></button></a></td>
我像这样编辑hrefhref=“#
之后,我只需在模式顶部编写以下代码:
<?php foreach ($customers as $get) { ?>
<div class="modal fade" id="<?php echo $get->cusId; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<?php } ?>
到底是什么问题?您可以在模式正文中输出您喜欢的任何内容。您尝试在其中获取客户数据的方法是什么,为什么您的方法不起作用?您想在模式中显示所有客户还是只显示一个?在客户表中单击客户的“信息”按钮时,只显示其中一个。实际按id显示信息。bo的版本是什么otstrap?@Mark您还需要将模态id
更新为info\u模态
,或者更改选择器
<td data-title="Edit" align="center"><a href="<?php echo base_url("customer_edit/edit/$customer->cusId"); ?>"><button class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></button></a> <a data-toggle="modal" href="#<?php echo $customer->cusId; ?>"><button class="btn btn-primary btn-xs"><i class="fa fa-eye"></i></button></a></td>
<?php foreach ($customers as $get) { ?>
<div class="modal fade" id="<?php echo $get->cusId; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<?php } ?>