ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

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

September 24, 2012 3:54pm

Subscribe [2]
  • #1 / Sep 24, 2012 3:54pm

    Kennedy

    1 posts

    Hi,

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

  • #2 / Sep 24, 2012 3:57pm

    CroNiX

    4713 posts

    What do you mean?

  • #3 / Sep 24, 2012 4:09pm

    Kennedy

    1 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.

  • #4 / Sep 24, 2012 4:24pm

    CroNiX

    4713 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);
    }
  • #5 / Sep 24, 2012 4:34pm

    CroNiX

    4713 posts

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

  • #6 / Sep 24, 2012 4:59pm

    skunkbad

    1326 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.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases