插入后的Codeigniter延迟数据

时间:2015-08-21 10:07:36

标签: php codeigniter

我正在跑步: - debian-linux-gnu - codeigniter 2.2.0 - db(遗留)中没有物理链接 - 版本:5.5.41-MariaDB-1~precision-log

问题: 我正在为网上商店写博客系统。填写表格(用实际博客的ckeditor)后,我会重定向到阅读页面/视图: redirect("/blog/read/" . $blog_id, "refresh");仅找不到数据。当我在imediatly之后刷新页面时,博客显示得很好。

我试着沉睡这个过程,但这没有用。所以我认为这不是数据库问题。由于该特定帖子的视图是新的,因此没有缓存。

控制器:

public function add_do() {

    //Image handling  
    if (!empty($_FILES['blog_file_img'])) {
        $path = $_FILES['blog_file_img']['name'];
        $ext = pathinfo($path, PATHINFO_EXTENSION);
        $fileData = $this->upload('blog_file_img', $this->now . '.' . $ext);
        $fileNames = $this->resize($fileData);
    }

    //Create blog
    $blog_data = array(
        "blog_img_original" => $fileData['file_name'],
        "blog_img_small" => $fileNames["small"],
        "blog_img_medium" => $fileNames['medium'],
        "blog_img_big" => $fileNames['big'],
        "blog_date_added" => $this->now,
        "blog_date_modified" => $this->now,
        "blog_created_by" => $this->user['userid'],
        "blog_modified_by" => $this->user['userid']
    );

    //Create blog description
    $blog_description_data = array(
        'language_id' => 1,
        'blog_title' => $this->input->post('blog_title', true),
        'blog_desc' => $this->input->post('blog_desc', true),
        'blog_text' => $this->input->post('blog_text', false)
    );

    $data = array_merge($blog_data, $blog_description_data);

    $blog_id = $this->blog_model->blog_new($data);

    redirect("/blog/read/" . $blog_id, "refresh");
}

读取控制器:

public function read($id){
    $this->_get_message();
    $blog_data = $this->blog_model->blog_entry($id);
    $this->load->view('header', $this->data_view);
    $this->load->view('blog/blog_entry', array('blog_data' => $blog_data));
    $this->load->view('blog/blog_right', array('blog_stats' => $this->blog_model->blog_most_popular()));
    $this->load->view('footer');
    $this->_debug();
}

添加模型

public function blog_new($data) {
    $this->db->trans_start();

    //Blog data extraction
    $blog_data = array(
        "blog_img_original" => $data['blog_img_original'],
        "blog_img_small" => $data["blog_img_small"],
        "blog_img_medium" => $data['blog_img_medium'],
        "blog_img_big" => $data['blog_img_big'],
        "blog_date_added" => $data['blog_date_added'],
        "blog_date_modified" => $data['blog_date_modified'],
        "blog_created_by" => $data['blog_created_by'],
        "blog_modified_by" => $data['blog_modified_by']
    );

    $blog_id = $this->new_blog($blog_data);

    //Blog description extraction
    $blog_description_data = array(
        'blog_id' => $blog_id,
        'language_id' => 1,
        'blog_title' => $data['blog_title'],
        'blog_desc' => $data['blog_desc'],
        'blog_text' => $data['blog_text']
    );

    $this->new_blog_description($blog_description_data);
    $this->db->trans_complete();

    return $blog_id;
}

private function new_blog($data) {

    $this->initialise('blog', 'blog_id');
    return $blog_id = $this->create($data);
}

private function new_blog_description($data) {

    $this->initialise('blog_description', 'blog_description_id');
    return $blog_description_id = $this->create($data);
}

阅读模型

public function blog_entry($id) {
    $this->db->select("*");
    $this->db->from("blog");
    $this->db->join("blog_description", "blog.blog_id = blog_description.blog_id");
    $this->db->join("blog_stats", "blog.blog_id = blog_stats.blog_id");
    $this->db->where("blog.blog_id", $id);
    $query = $this->db->get();

    //Add to views stats
    $this->blog_add_view($id);

    return $query->result_array();
}

0 个答案:

没有答案