为什么提交后必须单击刷新按钮才能从数据库中获取新数据


Why do I have to click refresh button to get new data from database after submit

我在提交表单时遇到问题,我有一个视图,显示数据库中的数据,并在每条弹出div 的记录旁边显示编辑按钮,其中包含一个表单来更新该特定记录。问题是,当我提交表单并将数据保存在数据库中时,视图将显示包含旧数据的记录,除非我在浏览器中点击刷新按钮。(代码点火器缓存设置为 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'));
    }
}
?>

因为您的获取请求:

$this->Product_model->get_all()->result_array(); 

在插入/更新请求之前:

$this->Product_model->update_settings($this->input->post('id'), $post);

因此,当您获得所有数据时,数据还不存在。

如果你把get放在你的if语句之后 - 那么它应该可以工作,例如:

if (isset($_POST['save'])) 
{
    // all your POST processing and saving...
}
$data['product'] = $this->Product_model->get_all()->result_array();