![]() |
Nested CI modules problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Nested CI modules problem (/showthread.php?tid=35056) |
Nested CI modules problem - El Forum - 10-18-2010 [eluser]DougW[/eluser] I have a main module, let's call it 'home.' It is a controller and a view. On this view I am using a jquery menu that loads sub-modules with ajax. Each sub-module is also a controller/view combination, such as 'dashboard.' I am trying to find a way to detect whether or not the sub-module was in fact loaded by the ajax call and thereby, valid. For example, I have a sub-module called 'dashboard' but I don't want users to be able to load the dashboard with just /dashboard. it should only be valid if called from the home module. There are probably a million ways to do this but I was wondering if there was a CI- tool or trick for detecting whether a CV construct was at the 'top' level or not besides looking at the url, as that clearly won't work in this case. Any clever ideas are appreciated. Nested CI modules problem - El Forum - 10-18-2010 [eluser]cahva[/eluser] Put this line to application/config/constants.php Code: define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); With that you can check if the request was an ajax request or not: Code: if (!IS_AJAX) Nested CI modules problem - El Forum - 10-18-2010 [eluser]DougW[/eluser] That did it. Thanks! Brilliantly simple. Just put the validation in any controller ad voila! Nested CI modules problem - El Forum - 10-18-2010 [eluser]DougW[/eluser] On the next phase of this, the session ID times out and I am prompted to login again which is expected. The problem is that even though I put: if (IS_AJAX) redirect("/"); in my login controller, the login screen is drawn in the div that was loaded by ajax. I want it to break out and go back to top level if a user's session times out. How can I do that? Nested CI modules problem - El Forum - 10-18-2010 [eluser]InsiteFX[/eluser] You need to extend the Session Class. Create a new file called MY_Session.php and add the below code to it. Then place the MY_Session.php file in application/libraries Code: class MY_Session extends CI_Session InsiteFX Nested CI modules problem - El Forum - 10-19-2010 [eluser]DougW[/eluser] Thanks. I tried this, put it in autoload and same result. Is there a particular way I need to call it? |