EllisLab text mark
Advanced Search
     
with CI, how to know if a specific view was loaded previously?
Posted: 24 September 2012 03:54 PM   [ Ignore ]
Joined: 2012-09-24
2 posts

Hi,

with CI, how to know if a specific view was loaded previously?

 
Posted: 24 September 2012 03:57 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3819 posts

What do you mean?

 Signature 
 
Posted: 24 September 2012 04:09 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-09-24
2 posts

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.

 
Posted: 24 September 2012 04:24 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3819 posts

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);
 Signature 
 
Posted: 24 September 2012 04:34 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3819 posts

You could also easily extend the loader class to track called views as well.

 Signature 
 
Posted: 24 September 2012 04:59 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1415 posts

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.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application