在链式名称空间中找不到类

时间:2014-02-12 13:29:31

标签: windows doctrine-orm doctrine zend-framework2

我在运行IIS的Windows Server中安装了ZendFramework和Doctrine 2的小应用程序。

该应用程序在linux下运行良好,但在我的Windows机器上,我收到以下错误:

An error occurred during execution; please try again later.

Doctrine\Common\Persistence\Mapping\MappingException

C:\inetpub\wwwroot\system\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:38
The class '' was not found in the chain configured namespaces App\Common\Entity
#0 C:\inetpub\wwwroot\system\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain.php(114): Doctrine\Common\Persistence\Mapping\MappingException::classNotFoundInNamespaces(false, Array)
#1 C:\inetpub\wwwroot\system\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMetadataFactory.php(113): Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass(false, Object(Doctrine\ORM\Mapping\ClassMetadata))
#2 C:\inetpub\wwwroot\system\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(302): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array)
#3 C:\inetpub\wwwroot\system\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(205): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('App\Common\Enti...')
#4 C:\inetpub\wwwroot\system\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php(268): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('App\Common\Enti...')
#5 C:\inetpub\wwwroot\system\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php(682): Doctrine\ORM\EntityManager->getClassMetadata('App\Common\Enti...')
#6 C:\inetpub\wwwroot\system\modules\App\Main\src\App\Main\Controller\IndexController.php(24): Doctrine\ORM\EntityManager->getRepository('App\Common\Enti...')
#7 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(83): App\Main\Controller\IndexController->indexAction()
#8 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#9 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#10 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#13 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#15 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 C:\inetpub\wwwroot\system\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 C:\inetpub\wwwroot\index.php(25): Zend\Mvc\Application->run()
#18 {main}

奇怪的是,在错误中..类名是空的。 可能是什么??

- 更新

所以,这就是我所说的

$this->getEntityManager()->getRepository('App\Common\Entity\Setting');

我的实体:

namespace App\Common\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Common\Model\Repository\Settings")
 * @ORM\Table(name="settings")
 * @ORM\HasLifecycleCallbacks
 */
class Setting {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer", nullable=false);
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="\Etc\App\Entity\User")
     * @ORM\JoinColumn(name="author", referencedColumnName="id", onDelete="SET NULL")
     */
    protected $author;

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getAuthor() {
        return $this->author;
    }

    public function setAuthor(\Etc\App\Entity\User $author) {
        $this->author = $author;
    }

}

- 更新2

namespace App\Common\Model\Repository;

class Settings {

    public function findAllFlatten() {
        // nothing relevant here.. 
    }

}



namespace Etc\App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity(repositoryClass="Etc\App\Model\Repository\User")
 * @ORM\Table(name="user")
 * @ORM\HasLifecycleCallbacks
 */
class User {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer", nullable=false);
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=48, unique=true, nullable=false)
     */
    protected $username;

    /**
     * @ORM\Column(type="string", length=64, nullable=false)
     */
    protected $password;

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getUsername() {
        return $this->username;
    }

    public function setUsername($username) {
        $this->username = $username;
    }

    public function getPassword() {
        return $this->password;
    }

    public function setPassword($password) {
        $this->password = $password;
    }

}

2 个答案:

答案 0 :(得分:0)

一切看起来都很正常,但唯一可以看到的是你的存储库没有扩展任何东西。它应该扩展doctrine repository类:

<? 
   namespace App\Common\Model\Repository; 

   use Doctrine\ORM\EntityRepository; 

   class Settings extends EntityRepository { 
       /// ... 

   } 

另外,您是否配置了所有命名空间?请记住,在配置文件中,您有教条配置,例如:

'doctrine' => array (
                'driver' => array (
                        'mi_driver' => array (
                                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                                'cache' => 'array',
                                'paths' => array (
                                        __DIR__ . '/PATH_TO_CLASS_FILES' 
                                ) 
                        ),


                        'orm_default' => array (
                                'drivers' => array (
                                        "NAMESPACE"=>"mi_driver", "NAMESPACE2"=>"mi_driver",

                                ) 
                        ) 
                ) 
        ) 
);

另外,检查自动装带器是否配置正确。尝试在代码new App\Common\Entity\Setting()

中的任何位置创建类的实例

答案 1 :(得分:0)

这可能有点晚了,但是在我看来,问题是作曲家的类缓存。我必须执行

composer dump-autoload

解决此问题。