Search code examples
phpcakephpclassloaderdirectory-structure

CakePHP showing include_once warnings


Suddenly, this website stop working and this errors appeared:

Warning: include_once(///controllers/site/default.php) [function.include-once]: failed to open stream: No such file or directory in /var/www/html/sitename.com/web/index.php on line 54

Warning: include_once() [function.include]: Failed opening '///controllers/site/default.php' for inclusion (include_path='.:/usr/share/pear') in /var/www/html/sitename.com/web/index.php on line 54

I don't know how CakePHP works, this is why I need help to figure out what happened (without anyone messing the code). The indicated files, that says that they're not there (No such file or directory), are exactly where the path describes.

I appreciate any help!

Error from line 54 in index.php:

include_once sprintf('%s/%s%s/%s.php', ROOT_PROJECT, CONTROLLERS_DIR, $url->tipo, 'default');

Solution

  • I believe the problem lies in the variables inserted through sprintf.

    There are some empty ones causing a lot of backslashes to be added to the string;

    Basically it says

    include('///controllers/site/default.php');
    

    (This is also visible in the generated php warning)

    Try catching empty variables or parsing the resulting string (making sure only 1 backslash exists between every parameter).

    If I'm right the next php command should work:

    include('/controllers/site/default.php');
    

    Hope this helps.