CodeIgniter Forums
$this->load->view unexpected behavior. - 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: $this->load->view unexpected behavior. (/showthread.php?tid=3178)



$this->load->view unexpected behavior. - El Forum - 09-14-2007

[eluser]cdmn[/eluser]
I did a little test to check my theory.

What i did:
1. Created a view in subfolder: view/subfolder/test_view.php
2. Created another view in sub/subfolder: view/subfolder/_subfolder/inc_view.php
3. Created controller to call test_view.php view
4. Edited Loader library to echo view $path

test_view.php code:

Code:
<?php

echo __FILE__;

$this->load->view('_subfolder/inc_view');

?>

I get:
Quote:/home/user/public_html/system/application/views/subfolder/test_view.php
/home/user/public_html/system/application/views/_subfolder/test_view.php

As you can see, im right now at "subfolder/test_view.php" and im trying to load view from "_subfolder/", but it searches for a view in a root directory. Shouldn't it be searching at "subfolder" directory as I'm already there?


$this->load->view unexpected behavior. - El Forum - 09-14-2007

[eluser]Matthew Pennell[/eluser]
No - the Loader class for views just looks in the /views directory, it won't take into account where in the file structure you happen to be when you call it.


$this->load->view unexpected behavior. - El Forum - 09-14-2007

[eluser]Michael Wales[/eluser]
Nope - all views are stored in the /views folder. The MVC framework (seperation of data, layout, and logic) produces this (and it's awesome).

With CI - always work off of the root. Images, Javascript, etc - reference it all from root - it will make your life much easier.