title: code igniter 2.0.3 loader add_package_path view cascading
body: <p>I'm not sure if I'm interpreting this wrong but please correct me if I am. I'm using Code Igniter's Loader class to load an application "package". It is working fine for the most part. However, one thing that's tripping me up is how the view paths are working (or not working).</p>
  
  <p>In the documentation (<a href="http://codeigniter.com/user_guide/libraries/loader.html" rel="nofollow">http://codeigniter.com/user_guide/libraries/loader.html</a>), it says:</p>
  
  <p>"By Default, package view files paths are set when add_package_path() is called. View paths are looped through, and once a match is encountered that view is loaded.</p>
  
  <p>In this instance, it is possible for view naming collisions within packages to occur, and possibly the incorrect package being loaded. To ensure against this, set an optional second parameter of FALSE when calling add_package_path()."</p>
  
  <p>This is the example code they give:</p>
  
  <pre><code>$this-&gt;load-&gt;add_package_path(APPPATH.'my_app', TRUE);
  $this-&gt;load-&gt;view('my_app_index'); // Loads
  $this-&gt;load-&gt;view('welcome_message'); // Will not load the default welcome_message b/c the second param to add_package_path is TRUE
  
  // Reset things
  $this-&gt;load-&gt;remove_package_path(APPPATH.'my_app');
  
  // Again without the second parameter:
  $this-&gt;load-&gt;add_package_path(APPPATH.'my_app', TRUE);
  $this-&gt;load-&gt;view('my_app_index'); // Loads
  $this-&gt;load-&gt;view('welcome_message'); // Loads
  </code></pre>
  
  <p>I think there is a typo in the example code and they mean to pass in FALSE to the second call to add_package_path(). My interpretation of this is that, if you pass in FALSE, the view path of the package should be skipped and the original view path should be used.</p>
  
  <p>However, when I actually try to pass in FALSE, I am still getting the view from the external package (the view name exists in both the external package and the current application). Looking at the Loader class in /system/core/Loader.php, this is the definition of add_package_path():</p>
  
  <pre><code>public function add_package_path($path, $view_cascade=TRUE)
  {
      $path = rtrim($path, '/').'/';
  
      array_unshift($this-&gt;_ci_library_paths, $path);
      array_unshift($this-&gt;_ci_model_paths, $path);
      array_unshift($this-&gt;_ci_helper_paths, $path);
  
      $this-&gt;_ci_view_paths = array($path.'views/' =&gt; $view_cascade) + $this-&gt;_ci_view_paths;
  
      // Add config file path
      $config =&amp; $this-&gt;_ci_get_component('config');
      array_unshift($config-&gt;_config_paths, $path);
  }
  </code></pre>
  
  <p>What it does is add the package view path to the front of the view paths array, with a value of TRUE or FALSE.  In the function that actually loads the views, also in the Loader class and called _ci_load($_ci_data), this is the segment where it chooses the path of views to look in:</p>
  
  <pre><code>foreach ($this-&gt;_ci_view_paths as $view_file =&gt; $cascade)
  {
      if (file_exists($view_file.$_ci_file))
      {
          $_ci_path = $view_file.$_ci_file;
          $file_exists = TRUE;
          break;
      }
  
      if ( ! $cascade)
      {
          break;
      }
  }
  </code></pre>
  
  <p>It seems to me that if the view exists in the external package (since it will be at the from of the array from the call to add_package_path), it will be loaded regardless of whether the 2nd parameter in add_package_path is TRUE or FALSE. There's not too much documentation on this and I didn't see any bug reports filed for this. Again, my interpretation is that if the 2nd parameter passed in to add_package_path() is FALSE, the view path of the package should be skipped. I'm thinking that in _ci_load(), inside the check for cascade should be a continue instead of a break, and it should come before the check for the file.</p>
  
  <p>Is this a bug that I should report or am I interpreting something incorrectly here and the function is working as it should be?</p>