CodeIgniter Forums
$this->load->view from relative path. - 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 from relative path. (/showthread.php?tid=11934)



$this->load->view from relative path. - El Forum - 09-29-2008

[eluser]Moon 111[/eluser]
Is it possible to execute $this->load->view($path) where $path is a relative path?


$this->load->view from relative path. - El Forum - 09-29-2008

[eluser]xwero[/eluser]
the start of the view path is set in the load->_ci_view_path variable so you can do
Code:
$this->load->_ci_view_path = './views/';
You could use a relative path but i wouldn't recommend it because the relative path is related to the url so if the url changes later on you have to change the _ci_view_path too.


$this->load->view from relative path. - El Forum - 09-29-2008

[eluser]Colin Williams[/eluser]
Quote:because the relative path is related to the url

Actually, no it isn't. The request doesn't come from a client, it's happening server-side. It will relative to the location of the script being executed, which is typically index.php, the front controller. At least that's what I think this morning before tea or coffee...


$this->load->view from relative path. - El Forum - 09-29-2008

[eluser]xwero[/eluser]
Colin you are right i was mixing it up with the relative paths of assets.


$this->load->view from relative path. - El Forum - 09-30-2008

[eluser]Phil Sturgeon[/eluser]
I have called views with the following and it works fine (where themes is a folder next to views).

Code:
$this->load->views('../themes/whatever/layout.php', $data);