更新时间:2023-12-04 10:05:28
嘿,在您的控制器中创建一个名为Modal.php的文件,并将此代码粘贴到此
Hey Create a file named Modal.php in your controller and paste this code in this
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Modal extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper(array('form', 'url'));
/*cache control*/
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
}
/***default functin, redirects to login page if no admin logged in yet***/
public function index()
{
}
/*
* $page_name = The name of page
*/
function popup($page_name = '' , $param2 = '' , $param3 = '')
{
//$account_type = $this->session->userdata('login_type');
$page_data['param2'] = $param2;
$page_data['param3'] = $param3;
$this->load->view( $page_name.'.php' ,$page_data);
}
}
和 查看所有用户
<?php
$count = 1;
foreach ($ro as $r)
{
?>
<tr>
<td scope="row"><?php echo $count++?></td>
<td>
<?php echo $r->username; ?>
</td>
<td>
<button onclick="showAjaxModal('<?php echo site_url(); ?>/modal/popup/details/<?php echo $r->username; ?>')">Details</button>
</td>
</tr><?php } ?>
还有一些html
<div class="modal fade" id="modal_ajax" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">User Details</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
和一些javascript
and some javascript
<script>
function showAjaxModal(url)
{
// SHOW AJAX RESPONSE ON REQUEST SUCCESS
jQuery.ajax({
url: url,
success: function(response)
{
jQuery('#modal_ajax .modal-body').html(response);
jQuery('#modal_ajax').modal('show', {
backdrop: 'static',
keyboard: false
});
}
});
}
</script>
最后在application/views文件夹中创建一个名为details.php的文件,然后写入
And finally create a file named details.php in your application/views folder and Write
<?php
$this->db->where('username', $param2);
$query = $this->db->get('user');
$details = $query->row();
print_r($details);
?>