0

I have a controller where i have a method called index. In this method i am retrieveing data from database and using a paging library setting variables for view for paging. When i add a new record i am hitting another function using ajax. There after insertion i call

$this->index();

Now in index i am checking a condition

if($this->input->is_ajax_request()){
    //dont load header and footer
}

but the problem is that when i come to index from my save function it looses the ajax request and my condition in index function in not checked and header and footer is always loaded. I want the ajax request still be available even if i jump from one method of codeigniter to another? Any suggestion? Or alter native. Because i dont want to create another function where create the paging again with header and footer ommited.

1 Answer 1

1

Something that might be useful is CodeIgniter's session class which has a flashdata method. Flashdata is a bit of session data that is only stored for the next server request, then it is deleted.

In your save function, you could have this at the end:

$this->session->set_flashdata('ajax', true);

and as part of the condition in your index function, you could have:

if($this->input->is_ajax_request() || $this->session->flashdata('item')){
    //dont load header and footer
}

This would then check that the request was actually an ajax request OR that a session variable has been temporarily set to tell CodeIgniter that it should be treated like an ajax request.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you this solved my problem i have never put a glance on flash data but now i am glad to have learned it
also i have found instead of using $this->index(); redirect(myurl) is working well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.