phpzend-framework2zend-autoloader

StandardAutoload doesn't work, while ClassAutoload does


I receive php fatal error "Class not found" while working on a test project (trying to learn ZF2).

    return array(
        'Zend\Loader\ClassMapAutoloader' => array(
            __DIR__ . '/classmap.php',
        ),
        'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
            ),
        ),
    );

Problem is simple, If I dont include my classmap, my entites dosnt load automatically, which is "okay" (as in it works now), but I would really like to know where the problem is and what is wrong...

my classmap.php file looks like this:

<?php
// Generated by Zend Framework 2
return array(
        'Common\Entity\Property' => __DIR__ . '/src/Common/Entity/property.php',
        'Common\Entity\Domain'   => __DIR__ . '/src/Common/Entity/domain.php',
        'Common\Module'          => __DIR__ . '/Module.php',
);

My error log looks like this:

[Sun Nov 30 17:16:40 2014] [error] [client 172.30.30.6] PHP Fatal error: 
    Class 'Common\\Entity\\Domain' not found in
     /var/www/hosts.legetimen.no/module/Frontpage/src/Frontpage/Controller/IndexController.php
     on line 38

(I have testet my Modeule.php with die("test"); to make sure it is loaded etc)

[EDIT] Directory structure of my module Common:

$ tree Common
Common
├── classmap.php
├── config
│   └── module.config.php
├── Module.php
└── src
    └── Common
        ├── Controller
        └── Entity
            ├── domain.php
            └── property.php

Thanks!


Solution

  • In your error message you have Class 'Common\\Entity\\Domain' not found in... so standard autoloader is looking for Domain.php file not for domain.php so simply change to upper case first letter of filenames.

    ClassMapAutoloader don't have this issue because for example Common\Entity\Property is mapping correctly to /src/Common/Entity/property.php.