0

Good afternoon,

I have a problem with the load() method of CodeIgniter. In local all work great. But when I tries to check my application in an online server I get problems <=> Unable to load the requested file: warning/info

The solution I found is to do this <=>

(1) In local

public function test() {
         $this->load->view('warning/info');
    }

(2) In the online server I have to specify the extension like that

public function test() {
     $this->load->view('warning/info.php');
}

I do not know why I have to dis this ? If someone know why can you explain me please.

Thank you very much and I sorry I am not fluent in english but I hope you can understand my message.

Sudipta
  • 4,773
  • 2
  • 27
  • 42
  • See this : [Remove .php extensions with .htaccess](http://stackoverflow.com/questions/9635524/remove-php-extensions-with-htaccess-without-breaking-directoryindex). It's relative to the server configuration. Adding a rule in your `.htaccess` will allow you do ommit the `.php` extension. By the way, [`load`](http://ellislab.com/codeigniter/user-guide/libraries/loader.html) isn't a method but an attribute (instance of Loader Class) – Brewal Oct 23 '13 at 14:40

1 Answers1

0

Identifying the problem

I've had a look in system/core/Loader.php, in the _ci_load() method, and I've extracted the code that seems to cause your problem:

#/system/core/Loader.php::_ci_load

$_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
$_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view;

foreach ($this->_ci_view_paths as $view_file => $cascade)
{
        if (file_exists($view_file.$_ci_file))
        {
                $_ci_path = $view_file.$_ci_file;
                $file_exists = TRUE;
                break;
        }

        if ( ! $cascade)
        {
                break;
        }
}

....

if ( ! $file_exists && ! file_exists($_ci_path))
{
        show_error('Unable to load the requested file: '.$_ci_file);
}

Fixing the problem

I've had a look at the methods used, and all of them seem to support PHP 4.0.3 onwards, so your issue is most likely not one to do with incompatible versions of PHP.

The code that seems to trigger your issue is here:

if ( ! $file_exists && ! file_exists($_ci_path))
{
        show_error('Unable to load the requested file: '.$_ci_file);
}

Now, my guess is that it works when you add the .php extension because this method actually passes:

file_exists($_ci_path)

A possible action would be to see what happens to the $file_exists variable, since it's only set to true when this happens:

if (file_exists($view_file.$_ci_file))

Additional info that may help

There is also an interesting comment on the file_exists method on php.net:

file_exists will have trouble finding your file if the file permissions are not read enabled for 'other' when not owned by your php user. I thought I was having trouble with a directory name having a space in it (/users/andrew/Pictures/iPhoto Library/AlbumData.xml) but the reality was that there weren't read permissions on Pictures, iPhoto Library or AlbumData.xml. Once I fixed that, file_exists worked.

Perhaps you could post the permissions on those files or try exploring there.

You may also try debugging in the system class and looking to find out if anything is going wrong in there. It's highly weird, since I've never encountered anything similar myself, and to be honest, I can't see how the library would have a slip-up in there - it's most likely got something to do with permissions

Petre Pătraşc
  • 2,203
  • 2
  • 19
  • 17