3

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 the scripts 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?

Joe W
  • 998
  • 6
  • 16
  • 36
  • Are you sure what permissons enought? ps chmod 777 -R /var/www/ – NiLL Jul 12 '11 at 13:39
  • Yes, they're set at 744. – Joe W Jul 12 '11 at 13:43
  • May be you try use base_url().'assets/themes'.$theme.'/scripts/includes.php' ? – NiLL Jul 12 '11 at 13:51
  • @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? – Damien Pirsy Jul 12 '11 at 13:52
  • @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. – Joe W Jul 12 '11 at 14:07
  • Why you use a $this->load->file(), not a reqire_once or include? – NiLL Jul 12 '11 at 14:17
  • @Joe try `echo $this->load->file($includes_url,TRUE)` inside a view for example, and see if you still get the error – Damien Pirsy Jul 12 '11 at 14:24
  • Firstly 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. – Joe W Jul 12 '11 at 14:26
  • @Joe Was just to make sure ;) Can I ask you what does 'include.php' contains that cannot be contained inside a view file? – Damien Pirsy Jul 12 '11 at 14:35
  • It includes – Joe W Jul 12 '11 at 14:43
  • 1
    Yes, 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. – Damien Pirsy Jul 12 '11 at 14:51

1 Answers1

3

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]
Pawan Choudhary
  • 1,073
  • 1
  • 10
  • 20
  • I'm not sure that's it, or I wouldn't be able to access any of the other files in the folder? – Joe W Jul 12 '11 at 16:55