我有一个codeigniter网站正在运行。一旦用户在页面上执行了操作,该页面似乎仍保留在浏览器中,并且页面上的数据不会刷新。即使在页面上的网格中添加或删除了记录,也不会显示该记录。我在页面上打印出变量,新数据总是在那里。我试图强制浏览器刷新:
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
这没有效果。下面是插入和选择视图的示例:
添加新记录控制器:
function add_new() {
$current_date = date('Y-m-d');
$data = array(
'catalogue_name' => $_POST['catalogue_name'] ,
'creation_date' => $current_date
);
$this->load->model('catalogue_model');
$last_id = $this->catalogue_model->add_catalogue($data);
$data['catalogue_id'] = $last_id;
redirect('catalogues/edit/'.$last_id);
}
型号:
function add_catalogue($data){
$this->db->insert('catalogue', $data);
return $this->db->insert_id();
}
查看:
<div class="container">
<div class="row">
<div class="row">
<div class="searchable-container">
<form action="<?php echo base_url('index.php/catalogues/add_new'); ?>" method="POST" role="form" id="name_catalogue">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<label>Catalogue Name</label>
<input type="text" name="catalogue_name" id="catalogue_name" class="form-control" title="">
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<button type="submit" class="btn btn-block btn-info">Create Catalogue</button>
</div>
</form>
</div>
</div>
</div>
</div>
然后是选择和显示控制器:
public function index() {
$this->output->set_template('default');
$data['catalogues'] = $this->catalogue_model->get_catalogues();
$this->load->view('catalogues/list', $data);
}
型号:
function get_catalogues() {
$this->db->select('*');
$this->db->from('catalogue');
$query = $this->db->get();
return $query->result();
}
查看:
<div class="container">
<?php if ($this->session->flashdata('message')) :?>
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php echo $this->session->flashdata('message');?>
</div>
<?php endif ; ?>
<div class="row">
<div class="row">
<a class="btn btn-large btn-block btn-success" href="<?php echo base_url('index.php/catalogues/new_catalogue'); ?>" role="button">Add New Catalogue</a>
</div>
<hr>
<div class="row">
<?php foreach ($catalogues as $catalogue): ?>
<div class="col-md-12">
<div class="col-md-3">
<h4><?php echo $catalogue->catalogue_name ?></h4>
</div>
<div class="col-md-3">
<h4><?php echo $catalogue->creation_date ?></h4>
</div>
<div class="col-md-3">
<a class="btn btn-large btn-block btn-default" href="<?php echo base_url('index.php/catalogues/edit'); ?>/<?php echo $catalogue->id; ?>" role="button">View</a>
</div>
<div class="col-md-3">
<a class="btn btn-large btn-block btn-danger" href="<?php echo base_url('index.php/catalogues/delete_catalogue'); ?>/<?php echo $catalogue->id; ?>" role="button">Delete Catalogue</a>
</div>
<hr>
</div>
<?php endforeach; ?>
</div>
<?php
$last = $this->uri->total_segments();
$catalogue_id = $this->uri->segment($last);
?>
</div>
</div>
因此,在此处添加记录时,记录会显示在数据库中,但一旦您转到&#34;列表&#34;就不会在视图中显示。页。如果我使用print_f
打印出数据,则会打印新数据,但不会显示在html中。
它看起来不像是一个codeigniter问题,但我可能错了。我使用bootstrap 3作为主题。
<html lang="en">
<head>
<title></title>
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<!-- Le styles -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link href="/assets/themes/default/hero_files/bootstrap-responsive.css" rel="stylesheet">
<link href="/assets/themes/default/css/general.css" rel="stylesheet">
<link href="/assets/themes/default/css/custom.css" rel="stylesheet">
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript" src="/assets/js/core.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="/assets/themes/default/js/bootstrap.js"></script>
<script type="text/javascript" src="/assets/themes/default/js/bootstrap-confirmation.min.js"></script>
<script src="/assets/grocery_crud/themes/bootstrap/js/bootstrap/dropdown.min.js"></script>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="/assets/themes/default/images/favicon.png" type="image/x-icon"/>
<meta property="og:image" content="/assets/themes/default/images/facebook-thumb.png"/>
<link rel="image_src" href="/assets/themes/default/images/facebook-thumb.png" />
<style type="text/css">
</style>
</head>
答案 0 :(得分:0)
此问题已通过迁移到新的托管服务提供商来解决。托管服务提供商更改了他们的托管环境,并且codeigniter会话停止了工作。之前发生过另一个我的codeigniter程序。因此,如果您遇到类似问题,请在另一台服务器上设置localhost或托管并在那里测试您的代码。
识别此问题的其他方法。如果您的程序仅允许用户查看他们创建的数据,则使用不同的用户名登录将显示相同或所有数据。
在一个浏览器上登录该程序,转到需要身份验证的记录,以查看,将该URL复制并粘贴到其他浏览器中。如果您看到该页面,则会话无法正常运行。