我遇到了提交表单的问题,我有一个视图,它显示来自数据库的数据,每个记录旁边的编辑按钮弹出 div 并带有一个表单来更新该特定记录。问题是当我提交表单并将数据保存在数据库中时,视图会显示带有旧数据的记录,除非我在浏览器中点击刷新按钮。(codeigniter 缓存设置为 FALSE)
控制器:
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Product extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('Table');
$this->load->library('DX_Auth');
// $this->load->library('pagination');
$this->load->helper('form');
$this->load->helper('url');
// Protect entire controller so only admin,
// and users that have granted role in permissions table can access it.
$this->dx_auth->check_uri_permissions();
$this->load->model('Product_model');
$this->load->library('Form_validation');
}
function index($sort = 0, $offset = 0) {
$data['product'] = $this->Product_model->get_all()->result_array();
if (isset($_POST['save'])) {
$this->form_validation->set_rules('link', 'Link', 'trim|required|xss_clean|prep_url');
$this->form_validation->set_rules('video', 'Video', 'trim|required|xss_clean|prep_url');
if ($this->form_validation->run() === TRUE) {
$post = $this->input->post();
if(!isset($post['link_target_blank'])){
$post['link_target_blank'] = 0;
}
unset($post['save']);
unset($post['id']);
$this->Product_model->update_settings($this->input->post('id'), $post);
}
}
// Load view
$header_data['title'] = 'Game Product';
$this->load->view($this->config->item('header_view'), $header_data);
$this->load->view($this->config->item('blocks_view') . 'head_block');
$this->load->view($this->config->item('menus_view') . 'main_menu');
$this->load->view('backend/product', $data);
$this->load->view($this->config->item('footer_view'));
}
}
?>