Unable to load the requested file - CodeIgniter
i think you're using .htaccess file with codeigniter which is causing you problem in getting the exact path of the php file you wish to include. rename the word library in the below code with the name of the PARENT folder which contain the include file and then update it with your existing .htaccess file.
RewriteEngine on RewriteCond $1 !^(index\.php|library|user_guide|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L]
Related videos on Youtube
Joe W
Updated on November 02, 2020Comments
-
Joe W over 3 years
I'm trying to include a PHP file called
includes.php
which is not contained within the normal Views folder. The file contains links to the JS files to be loaded with this particular theme.includes.php
resides within thescripts
folder:| assets | | themes | theme_name | css | img | scripts | application | system
In my controller I'm using
$this->load->helper('url')
which always works fine, and within the View I'm trying to call the following:$includes_url = asset_url() . 'themes/' . $theme . '/scripts/includes.php'; $this->load->file($includes_url);
The URL seems correct as when I echo
$includes_url
the path is fine.Despite this, I'm getting the error:
An Error Was Encountered Unable to load the requested file: includes.php
What other issues could there be besides Code Igniter not finding the file with that filepath? Have I missed something obvious?
-
NiLL almost 13 yearsAre you sure what permissons enought? ps chmod 777 -R /var/www/
-
Joe W almost 13 yearsYes, they're set at 744.
-
NiLL almost 13 yearsMay be you try use base_url().'assets/themes'.$theme.'/scripts/includes.php' ?
-
Damien Pirsy almost 13 years@NiLL I too thought at that, as I never saw asset_url() function, but he says the path echoes correctly...@Joe since it seems you have different themese, is $theme the right place where you put the file?
-
Joe W almost 13 years@NiLL & @Damien - thanks for your input. The asset_url() function is one I use myself to create the path to the asset files. It works absolutely fine for me when using different themes. As I say, when I test the path it works fine. For example, I changed the URL from includes.php to an image in the same folder and I was able to navigate to that image just fine.
-
NiLL almost 13 yearsWhy you use a $this->load->file(), not a reqire_once or include?
-
Damien Pirsy almost 13 years@Joe try
echo $this->load->file($includes_url,TRUE)
inside a view for example, and see if you still get the error -
Joe W almost 13 yearsFirstly because I want to try and use the CodeIgniter syntax where possible, but also because I believe that if I use my asset_url function with require_once then I need allow_url_include to be set to true in php.ini - this is OK on my local server, but some hosts don't allow it for security reasons.
-
Damien Pirsy almost 13 years@Joe Was just to make sure ;) Can I ask you what does 'include.php' contains that cannot be contained inside a view file?
-
Joe W almost 13 yearsIt includes <script> links to JS files that are loaded per theme. So because each theme might load different JS files, it's best to load them only when necessary. If I can keep all related files within the specific theme folder, then that's the best scenario. AFAIK, I can only call
$this->load->view()
on files kept within theViews
folder. -
Damien Pirsy almost 13 yearsYes, but you can specify subfolders inside views. So, althought it will lead to 'folder-duplication', you would avoid this unknown behaviour. It's an ugly workaround so far, I know...Another thing: give 'include.php' the same permission of a normal view file.
-
-
Joe W almost 13 yearsI'm not sure that's it, or I wouldn't be able to access any of the other files in the folder?