Welcome Guest, Not a member yet? Register   Sign In
Up-to-date data
#1

[eluser]brentconey[/eluser]
Hello Everyone,
I've just recently started developing with CI, and so far I love it. I have a problem that I'm sure is something stupid on my part, but I can't figure out how to fix it, so here it goes.

I have a web application that has user submit a form, then an admin reviews the form and can edit it if they need to.
My problem is after they edit it and go back (by clicking an a href) to the list of submissions it has the old data there. So my problem is for whatever reason when I move around in the web app the data is not staying "up to date". I have checked my db and as soon as it updates in the web app the changes are reflected in the db.

I have tried at the beginning of my functions dumping the array I shove the data into ($data = array(); ) before I dump the data in thinking it was just not replacing it. I have also thought maybe CI was caching the db, but I also run $this->db->cahce_delete__all(); and nothing seems to give me "fresh" data when I move from page to page.

Any Suggestions?
#2

[eluser]danmontgomery[/eluser]
Suggestion: If you want help, post some code Tongue
#3

[eluser]Jan_1[/eluser]
how does "after they edit it and go back (by clicking an a href)" look like?
any code?
#4

[eluser]brentconey[/eluser]
Here is my admin controller. When you hit the index it just loads the view of the submissions.
Code:
function index(){
        $data = array();
        $this->load->model('admin_model');
        $data['submissions'] = $this->admin_model->getSubmissionList();
        $this->load->view('adminlist-view', $data);
    }
Then when the click a submission it loads the view function which looks like this:
Code:
function view($id = NULL){
        date_default_timezone_set('America/Chicago');
        $this->load->model('admin_model');
        $yearNow = date("Y");
        $years = range(($yearNow-5), $yearNow);
        $data['years'] = $years;
        $data['yearNow'] = $yearNow;
        $data['submission_data'] = $this->admin_model->getSubmissionData($id);
        $this->load->view('adminsubmission-view',$data);
    }
So the workflow is they see the index which gives a list of submissions, when they click a submission it goes to the view function which pulls the data for the submission they chose. Inside the submission they can edit the data. at the bottom of the adminsubmission-view there is a link back to the index.
Code:
<p class="center"><a href="&lt;?php echo base_url();?&gt;index.php/admin/">Return to submissions</a></p>
If they edit the submission and they change things like the title or something when you click "return to submissions" it doesn't pull the updated data.

Does this make sense now?
Sorry for posting no code Sad
#5

[eluser]brentconey[/eluser]
I should also mention I didn't add the code that runs the update, because I didn't think it would help anything, but just know that there is an update routine that is running if they do change something that commits it to the DB.
#6

[eluser]Jan_1[/eluser]
I can't see where an update should be done. no link to an update function. but i understood that the update is also in the db. Did you check the caching of your browser?
#7

[eluser]brentconey[/eluser]
Just so you can see the update looks like this:
Code:
function update(){
        $this->db->cache_delete_all();
        $id = $this->input->post('id');
        $trackTitle = $this->input->post('track_title');
        $courseTitle = $this->input->post('course_title');
        $presenter = $this->input->post('presenter');
        $institution = $this->input->post('institution');
        $gLevel = $this->input->post('grade_level');
        $yearCreated = $this->input->post('year');
        $description = $this->input->post('description');
        $data = array(
                'track_title' => $trackTitle,
                'course_title' => $courseTitle,
                'presenter' => $presenter ,
                'g_level' => $gLevel ,
                'year_created' => $yearCreated ,
                'description' => $description ,
                'institution' => $institution
            );    
        $this->db->where('id', $id);
        if($this->db->update('submissions', $data)){
            $updateData['id'] = $id;
            sleep(2);
            $data = array();
            $this->view($id);
        }else{
            echo "error updating";
        }
        
    }
#8

[eluser]brentconey[/eluser]
Nobody?
#9

[eluser]faxtion[/eluser]
I had a similar issue with a site I developed, and I found that using redirect was my solution.

Easy way of doing it is by using form validation to check one or more items of the form, the form post is to the update function. then you have an IF statement to check if the validation was run if errors returned it will show errors and redisplay form, otherwise if the validation rules pass it will redirect to the page.

Sample Code
Code:
if ($this->form_validation->run() == FALSE) {
                    $data['news'] = $this->adminmodel->getNew($id);
                    $this->load->view('admin/edit', $data);
                } else {
                    $update = $this->adminmodel->updateNews();
                    $data['error'] = 'News Entry Added';
                    $data['news'] = $this->adminmodel->getNews();

                    redirect('/admin/news','refesh');
                }




Theme © iAndrew 2016 - Forum software by © MyBB