Welcome Guest, Not a member yet? Register   Sign In
Loading a View File Outside the View Directory
#1

[eluser]jeffpeck[/eluser]
I am building a site that has all of the pages in a hierarchy in a separate directory called "site". Each page includes a document called "meta.xml" as well as a few other files.

Possibly the most important one is called "content.php", which needs to processed as a Codeigniter View file.

I try to send it's absolute path (the real path starting at the server's root) to $this->load->view() and it returns an error.

Is there any other way to do this?

If I could get the contents of this file using read_file(), could I then pass the PHP parsed contents to the output buffer in the appropriate location?

Any help would be appreciated.

Thanks,
Jeff
#2

[eluser]jeffpeck[/eluser]
I was able to access it with a relative path using ../../../

Is it a bug that it will not work with an absolute path?
#3

[eluser]frist44[/eluser]
Can you get to file itself using an absolute path in the browser? not from code...
#4

[eluser]jeffpeck[/eluser]
No, the file is only accessible at path that can be accessed by the system (i.e. not by HTTP)
#5

[eluser]SpooF[/eluser]
If you want to change the directory where you site loads views from you will need to create a MY_Loader class and extend the CI_Loader class (best practice) and then edit the constructor which looks like this:

Code:
function CI_Loader()
    {    
        $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE;
        $this->_ci_view_path = APPPATH.'views/';
        $this->_ci_ob_level  = ob_get_level();
                
        log_message('debug', "Loader Class Initialized");
    }

You could also change the view function so it takes an argument that will change the path where it looks if you want.
#6

[eluser]jeffpeck[/eluser]
Thank you, that's a good solution.

Any idea on how to modify to make it take an absolute path?
#7

[eluser]SpooF[/eluser]
Well you can set _ci_view_path to blank, but that means you will have to use an absolute path every time unless you do add some more of parameter that says to use an absolute or a relative path.
#8

[eluser]jeffpeck[/eluser]
...or to determine if it is absolute or relative by whether or not it begins with a '/'.




Theme © iAndrew 2016 - Forum software by © MyBB