Hi,
with CI, how to know if a specific view was loaded previously?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
September 24, 2012 3:54pm
Subscribe [2]#1 / Sep 24, 2012 3:54pm
Hi,
with CI, how to know if a specific view was loaded previously?
#2 / Sep 24, 2012 3:57pm
What do you mean?
#3 / Sep 24, 2012 4:09pm
I have a view that can be called in any place of controller or another view, and to prevent it being called again I wanna check if this view was loaded previously.
#4 / Sep 24, 2012 4:24pm
Not easily.
Check the results of
print_r($this->load);(or even better use a stepping debugger)
in a controller to see what the loader class keeps track of. It does track loaded classes/models/helpers/cached_variables and a few other things, but not views specifically. There is another tracked category for loaded_files, but I don’t think it shows view files either (shows config files, etc).
I think you might be able to throw a
define('VIEW_LOADED', TRUE);in there when you do load that view, and check to see if VIEW_LOADED is defined in the other places where you need to check for it.
if ( ! defined('VIEW_LOADED'))
{
$this->load->view('your_view');
define('VIEW_LOADED', TRUE);
}#5 / Sep 24, 2012 4:34pm
You could also easily extend the loader class to track called views as well.
#6 / Sep 24, 2012 4:59pm
You could easily extend the view method of the Loader class. Each time a view is loaded, add it to a new class member (array with public access). Then, at any point you could check if that array is holding the view as an element.