Welcome Guest, Not a member yet? Register   Sign In
$this->load->view unexpected behavior.
#1

[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?
#2

[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.
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB