Problem with Doctrine 2: it can't find an Entity File


I’m getting this error on my shared hosting account :sick::

Warning: require(/Entities/Account.php) [function.require]: failed to open stream: No such file or directory in /home/undo/public_html/hidraserca/library/Doctrine/Common/ClassLoader.php on line 148

Fatal error: require() [function.require]: Failed opening required ‘/Entities/Account.php’ (include_path=‘/home/undo/public_html/hidraserca/application/…/views:/home/undo/public_html/hidraserca/library:/home/undo/public_html/zf’) in /home/undo/public_html/hidraserca/library/Doctrine/Common/ClassLoader.php on line 148

It does work on my mac so I don’t know what’s happening. :injured:

That error is caused because this path ".../public_html/hidraserca/library:/home/undo/public_html/zf" isn’t a real file path.

The require function checks your path and if it isn’t real, it stops script execution.

That’s the include_path value. I don’t see what’s wrong with that :blush:.

The error “failed to open stream: No such file or directory” is caused by an incorrect file name. That or the folder permissions are wrongly set. :slight_smile:

The file is there, I checked. Also it works on my local dev environment.

What permissions do I have to set?

I think the path is incorrect. Try an absolute path from the home folder or a relative path to the file.


I don’t think is a good idea to start changing the code in the classes. I think it could solve the problem but it will fail someplace else and I’ll have to change the code again and again. :confused:

It won’t fail if you use absolute paths from the home folder.

What about the others ‘require()’ in the other files? :blush:

You should do that for all require, include, etc.

If you have a config file for your site, just set a root path in the config file. Assuming it’s in the root directory you could do it like so

defined('SITE_ROOT') ? null : define('SITE_ROOT', dirname(__FILE__));


defined('SITE_ROOT') ? null : define('SITE_ROOT', '/home/mysite/www');

Then do your includes as such


The real problem is that you don’t have your doctrine class loader setup correctly. The class loader always works with absolute paths. Your include path is irrelevant in this case. The /Entities/Whatever is the tip off.

Check or post your initialization code. Somewhere you have something like:
use Doctrine\Common\ClassLoader;

 $loader = new ClassLoader($nameSpace,$nameSpacePath);

That points your entity namespace to a specific directory containing your entities. It needs to be adjusted to match your server file layout.

I got this on my Bootstrap.php:

    protected function _initDoctrine() {


        $autoloader = Zend_Loader_Autoloader::getInstance();
        $classLoader = new \\Doctrine\\Common\\ClassLoader('Entities',
                        realpath(Zend_Registry::get('config')->resources->entityManager->connection->entities), 'loadClass');

        $autoloader->pushAutoloader(array($classLoader, 'loadClass'), 'Entities');

        $classLoader = new \\Doctrine\\Common\\ClassLoader('Repositories',
                        realpath(Zend_Registry::get('config')->resources->entityManager->connection->entities), 'loadClass');

        $autoloader->pushAutoloader(array($classLoader, 'loadClass'), 'Repositories');

On my application.ini I got this:

resources.entityManager.connection.entities = "/Library/Webserver/Documents/hidraserca/application/models"

It works on my local dev environment so there must be something I must check on my host but I don’t know what or where to check :sick:.

I’m not familiar enough with Zend to offer specifics but start by replacing:
resources.entityManager.connection.entities = “/Library/Webserver/Documents/hidraserca/application/models”
That might be all you need to get it to work. At some point you will need an ini file of some sort just for your shared host. If nothing else, your database passwords will probably be different as well as some paths.

If the above does not work then try changing:
$classLoader = new DoctrineCommonClassLoader(‘Entities’,
realpath(Zend_Registry::get(‘config’)->resources->entityManager->connection->entities), ‘loadClass’);
$classLoader = new DoctrineCommonClassLoader(‘Entities’,“/the/actual/shared/host/path/to/applications/models”),‘loadClass’);

In other words. hard code the path directly in the loader. If that works then at least you have confirmed the problem. Then you can figure out how to get the path from the zend configuration system.

If you still have problems then consider posting on the Zend board. I’m sure they can fix you right up.


It was right there and I didn’t see it.

From the beginning the problem was between the chair and the MacBook.

You’re a hero!

I am here:,-69.277079

  • Sent from my iPhone using Tapatalk