Exception 学说注释例外
我有5台服务器运行同一个应用程序(Zend+Doctrine),在最后一台服务器(最近安装)im上,我遇到了以下异常:Exception 学说注释例外,exception,doctrine,annotations,mapping,Exception,Doctrine,Annotations,Mapping,我有5台服务器运行同一个应用程序(Zend+Doctrine),在最后一台服务器(最近安装)im上,我遇到了以下异常: Application error Exception information: Message: Class Entity\User is not a valid entity or mapped super class. Stack trace: #0 /home/library/vendor/doctrine/2.0/Doctrine/ORM/Mapping/Driv
Application error Exception information:
Message: Class Entity\User is not a valid entity or mapped super class. Stack trace:
#0 /home/library/vendor/doctrine/2.0/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php(138): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass('Entity\User')
#1 /home/library/vendor/doctrine/2.0/Doctrine/ORM/Mapping/ClassMetadataFactory.php(282): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('Entity\User', Object(Doctrine\ORM\Mapping\ClassMetadata))
#2 /home/library/vendor/doctrine/2.0/Doctrine/ORM/Mapping/ClassMetadataFactory.php(176): Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('Entity\User')
#3 /home/library/vendor/doctrine/2.0/Doctrine/ORM/EntityManager.php(247): Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor('Entity\User')
#4 /home/library/vendor/doctrine/2.0/Doctrine/ORM/EntityManager.php(564): Doctrine\ORM\EntityManager->getClassMetadata('Entity\User')
#5 /home/imobfusion/public_html/application/modules/a1/controllers/IndexController.php(68): Doctrine\ORM\EntityManager->getRepository('Entity\User')
#6 /home/library/vendor/zend/1.11.3/Zend/Controller/Action.php(513): A1_IndexController->testDoctrineAction()
#7 /home/library/vendor/zend/1.11.3/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('testDoctrineAct...')
#8 /home/library/vendor/zend/1.11.3/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 /home/library/vendor/zend/1.11.3/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 /home/library/vendor/zend/1.11.3/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 /home/imobfusion/public_html/public/index.php(21): Zend_Application->run()
#12 {main}
Request Parameters:
array(3) { ["controller"]=> string(5) "index" ["action"]=> string(13) "test-doctrine" ["module"]=> string(2) "a1" }
php(138)上的looikng:
否则会引发异常
但我真的不知道会发生什么
有什么帮助或小费吗
Obs:
- /home/library/getDocComment不仅适用于此特定类和服务器:
用户类/实体:
<?php /** @Entity * @HasLifecycleCallbacks * @Table(name="user") */ namespace Entity; use Validation; use \DateTime; use \LogHelper; class User { ///////////////////////////////////////////////////////////////////////// // Properties // ///////////////////////////////////////////////////////////////////////// /** * @Id * @Column(type="integer") * @generatedValue(strategy="AUTO") */ protected $id; /** * @Column(type="integer") */ protected $type = 0; /** * @Column(length=50) */ protected $name; /** * @Column(length=50) */ protected $user_name; /** * @Column(length=100) */ protected $email; /** * @Column(length=14) */ protected $phone; /** * @Column(length=14) */ protected $cell_phone; /** * @Column(length=36) */ protected $password; /** * @Column(type="text",length=1000) */ protected $permissions; /** * @Column(type="text",length=1000) */ protected $time_table; /** * @Column(type="text",length=1000,nullable=true) */ protected $desktop; /** * @Column(type="boolean",nullable=true) */ protected $chat_on = 0; // Behaviors /** * @Column(type="datetime") */ protected $created_at; /** * @Column(type="datetime") */ protected $updated_at; /** * @Column(type="integer") * @version */ protected $version; ///////////////////////////////////////////////////////////////////////// // Relations // ///////////////////////////////////////////////////////////////////////// /** * @ManyToOne(targetEntity="Branch", inversedBy="users") * @JoinColumn(name="branch_id", referencedColumnName="id") */ private $branch; /** * @OneToMany(targetEntity="Property", mappedBy="captivator"); */ private $properties; /** * @OneToMany(targetEntity="KeyHistory", mappedBy="user"); */ private $key_histories; /** * @OneToMany(targetEntity="Presentation", mappedBy="user"); */ private $presentations; /** * @OneToMany(targetEntity="Log", mappedBy="user"); */ private $logs; /** * @OneToMany(targetEntity="Chat", mappedBy="user"); */ private $chats; ///////////////////////////////////////////////////////////////////////// // ForeingKey // ///////////////////////////////////////////////////////////////////////// /** * @Column(type="integer") */ protected $branch_id; ///////////////////////////////////////////////////////////////////////// // Getters/Setters // ///////////////////////////////////////////////////////////////////////// public function setId($value) {$this->id = $value;} public function getId() {return $this->id;} public function setType($value) {$this->type = $value;} public function getType() {return $this->type;} public function setName($value) {$this->name = $value;} public function getName() {return $this->name;} public function setUserName($value) {$this->user_name = $value;} public function getUserName() {return $this->user_name;} public function setEmail($value) {$this->email = $value;} public function getEmail() {return $this->email;} public function setPhone($value) {$this->phone = $value;} public function getPhone() {return $this->phone;} public function setCellPhone($value) {$this->cell_phone = $value;} public function getCellPhone() {return $this->cell_phone;} public function setPassword($value) {$this->password = $value;} public function getPassword() {return $this->password;} public function setPermissions($value) {$this->permissions = $value;} public function getPermissions() {return $this->permissions;} public function setTimeTable($value) {$this->time_table = $value;} public function getTimeTable() {return $this->time_table;} public function setDesktop($value) {$this->desktop = $value;} public function getDesktop() {return $this->desktop;} public function setChatOn($value) {$this->chat_on = $value;} public function getChatOn() {return $this->chat_on;} public function setBranch($value) {$this->branch = $value;} public function getBranch() {return $this->branch;} public function setBranchId($value) {$this->branch_id = $value;} public function getBranchId() {return $this->branch_id;} public function getCreatedAt() {return $this->created_at->format("d/m/Y H:i:s");} public function getUpdatedAt() {return $this->updated_at->format("d/m/Y H:i:s");} public function getVersion() {return $this->version;} ///////////////////////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////////////////////// public function __construct() { $this->created_at = $this->updated_at = new DateTime("now"); } ///////////////////////////////////////////////////////////////////////// // Hooks // ///////////////////////////////////////////////////////////////////////// /** * @PrePersist * @PreUpdate */ public function Validate() { $this->ApplyBehaviors(); $e = new ValidationException(); if(empty($this->name)) { $e->AppendError("O Campo nome não pode ser vazio.","name"); } if(empty($this->user_name)) { $e->AppendError("O Campo nome de usuário não pode ser vazio.","user_name"); } if(empty($this->email)) { $e->AppendError("O Campo email não pode ser vazio.","email"); } if($e->hasError()) throw $e; } /** * @PostPersist */ public function onPostPersist() { LogHelper::SaveAction(LogHelper::ACTION_ADD,LogHelper::ENTITY_USER,$this->getId()); } /** * @PostUpdate */ public function onPostUpdate() { LogHelper::SaveAction(LogHelper::ACTION_UPDATE,LogHelper::ENTITY_USER,$this->getId()); } /** * @PreRemove */ public function onPreRemove() { LogHelper::HoldId($this->id); } /** * @PostRemove */ public function onPostRemove() { LogHelper::SaveAction(LogHelper::ACTION_DELETE,LogHelper::ENTITY_USER,$this->id); } private function ApplyBehaviors() { $this->updated_at = new DateTime("now"); } ///////////////////////////////////////////////////////////////////////// // Helpers // ///////////////////////////////////////////////////////////////////////// public function syncronize($data) { $this->setType($data["type"]); $this->setName($data["name"]); $this->setUserName($data["user_name"]); $this->setEmail($data["email"]); $this->setPhone($data["phone"]); $this->setCellPhone($data["cell_phone"]); $this->setPermissions($data["permissions"]); $this->setTimeTable($data["time_table"]); $this->setDesktop($data["desktop"]); $this->setBranchId($data["branch_id"]); $this->setChatOn($data["chat_on"]); } public function toArray() { $data["id"] = $this->getId(); $data["type"] = $this->getType(); $data["name"] = $this->getName(); $data["user_name"] = $this->getUserName(); $data["phone"] = $this->getPhone(); $data["cell_phone"] = $this->getCellPhone(); $data["email"] = $this->getEmail(); $data["password"] = $this->getPassword(); $data["permissions"] = $this->getPermissions(); $data["time_table"] = $this->getTimeTable(); $data["desktop"] = $this->getDesktop(); $data["branch_id"] = $this->getBranchId(); $data["chat_on"] = $this->getChatOn(); $data["created_at"] = $this->getCreatedAt(); $data["updated_at"] = $this->getUpdatedAt(); return $data; } }
已解决: 错误:
// AnnotationDriver $driver = $config->newDefaultAnnotationDriver($options["entities_dir"]); $config->setMetadataDriverImpl($driver); var_dump($driver->getAllClassNames()); die();
<?php /** @Entity * @HasLifecycleCallbacks * @Table(name="user") */ namespace Entity; use Validation; use \DateTime; use \LogHelper;
<?php namespace Entity; use Validation; use \DateTime; use \LogHelper; /** @Entity * @HasLifecycleCallbacks * @Table(name="user") */
我在从Symfony中取出一些代码时遇到了自动加载实体的问题。尝试直接从引导文件中包含实体文件,看看是否有帮助
<?php /** @Entity * @HasLifecycleCallbacks * @Table(name="user") */ namespace Entity; use Validation; use \DateTime; use \LogHelper; class User { ///////////////////////////////////////////////////////////////////////// // Properties // ///////////////////////////////////////////////////////////////////////// /** * @Id * @Column(type="integer") * @generatedValue(strategy="AUTO") */ protected $id; /** * @Column(type="integer") */ protected $type = 0; /** * @Column(length=50) */ protected $name; /** * @Column(length=50) */ protected $user_name; /** * @Column(length=100) */ protected $email; /** * @Column(length=14) */ protected $phone; /** * @Column(length=14) */ protected $cell_phone; /** * @Column(length=36) */ protected $password; /** * @Column(type="text",length=1000) */ protected $permissions; /** * @Column(type="text",length=1000) */ protected $time_table; /** * @Column(type="text",length=1000,nullable=true) */ protected $desktop; /** * @Column(type="boolean",nullable=true) */ protected $chat_on = 0; // Behaviors /** * @Column(type="datetime") */ protected $created_at; /** * @Column(type="datetime") */ protected $updated_at; /** * @Column(type="integer") * @version */ protected $version; ///////////////////////////////////////////////////////////////////////// // Relations // ///////////////////////////////////////////////////////////////////////// /** * @ManyToOne(targetEntity="Branch", inversedBy="users") * @JoinColumn(name="branch_id", referencedColumnName="id") */ private $branch; /** * @OneToMany(targetEntity="Property", mappedBy="captivator"); */ private $properties; /** * @OneToMany(targetEntity="KeyHistory", mappedBy="user"); */ private $key_histories; /** * @OneToMany(targetEntity="Presentation", mappedBy="user"); */ private $presentations; /** * @OneToMany(targetEntity="Log", mappedBy="user"); */ private $logs; /** * @OneToMany(targetEntity="Chat", mappedBy="user"); */ private $chats; ///////////////////////////////////////////////////////////////////////// // ForeingKey // ///////////////////////////////////////////////////////////////////////// /** * @Column(type="integer") */ protected $branch_id; ///////////////////////////////////////////////////////////////////////// // Getters/Setters // ///////////////////////////////////////////////////////////////////////// public function setId($value) {$this->id = $value;} public function getId() {return $this->id;} public function setType($value) {$this->type = $value;} public function getType() {return $this->type;} public function setName($value) {$this->name = $value;} public function getName() {return $this->name;} public function setUserName($value) {$this->user_name = $value;} public function getUserName() {return $this->user_name;} public function setEmail($value) {$this->email = $value;} public function getEmail() {return $this->email;} public function setPhone($value) {$this->phone = $value;} public function getPhone() {return $this->phone;} public function setCellPhone($value) {$this->cell_phone = $value;} public function getCellPhone() {return $this->cell_phone;} public function setPassword($value) {$this->password = $value;} public function getPassword() {return $this->password;} public function setPermissions($value) {$this->permissions = $value;} public function getPermissions() {return $this->permissions;} public function setTimeTable($value) {$this->time_table = $value;} public function getTimeTable() {return $this->time_table;} public function setDesktop($value) {$this->desktop = $value;} public function getDesktop() {return $this->desktop;} public function setChatOn($value) {$this->chat_on = $value;} public function getChatOn() {return $this->chat_on;} public function setBranch($value) {$this->branch = $value;} public function getBranch() {return $this->branch;} public function setBranchId($value) {$this->branch_id = $value;} public function getBranchId() {return $this->branch_id;} public function getCreatedAt() {return $this->created_at->format("d/m/Y H:i:s");} public function getUpdatedAt() {return $this->updated_at->format("d/m/Y H:i:s");} public function getVersion() {return $this->version;} ///////////////////////////////////////////////////////////////////////// // Constructor // ///////////////////////////////////////////////////////////////////////// public function __construct() { $this->created_at = $this->updated_at = new DateTime("now"); } ///////////////////////////////////////////////////////////////////////// // Hooks // ///////////////////////////////////////////////////////////////////////// /** * @PrePersist * @PreUpdate */ public function Validate() { $this->ApplyBehaviors(); $e = new ValidationException(); if(empty($this->name)) { $e->AppendError("O Campo nome não pode ser vazio.","name"); } if(empty($this->user_name)) { $e->AppendError("O Campo nome de usuário não pode ser vazio.","user_name"); } if(empty($this->email)) { $e->AppendError("O Campo email não pode ser vazio.","email"); } if($e->hasError()) throw $e; } /** * @PostPersist */ public function onPostPersist() { LogHelper::SaveAction(LogHelper::ACTION_ADD,LogHelper::ENTITY_USER,$this->getId()); } /** * @PostUpdate */ public function onPostUpdate() { LogHelper::SaveAction(LogHelper::ACTION_UPDATE,LogHelper::ENTITY_USER,$this->getId()); } /** * @PreRemove */ public function onPreRemove() { LogHelper::HoldId($this->id); } /** * @PostRemove */ public function onPostRemove() { LogHelper::SaveAction(LogHelper::ACTION_DELETE,LogHelper::ENTITY_USER,$this->id); } private function ApplyBehaviors() { $this->updated_at = new DateTime("now"); } ///////////////////////////////////////////////////////////////////////// // Helpers // ///////////////////////////////////////////////////////////////////////// public function syncronize($data) { $this->setType($data["type"]); $this->setName($data["name"]); $this->setUserName($data["user_name"]); $this->setEmail($data["email"]); $this->setPhone($data["phone"]); $this->setCellPhone($data["cell_phone"]); $this->setPermissions($data["permissions"]); $this->setTimeTable($data["time_table"]); $this->setDesktop($data["desktop"]); $this->setBranchId($data["branch_id"]); $this->setChatOn($data["chat_on"]); } public function toArray() { $data["id"] = $this->getId(); $data["type"] = $this->getType(); $data["name"] = $this->getName(); $data["user_name"] = $this->getUserName(); $data["phone"] = $this->getPhone(); $data["cell_phone"] = $this->getCellPhone(); $data["email"] = $this->getEmail(); $data["password"] = $this->getPassword(); $data["permissions"] = $this->getPermissions(); $data["time_table"] = $this->getTimeTable(); $data["desktop"] = $this->getDesktop(); $data["branch_id"] = $this->getBranchId(); $data["chat_on"] = $this->getChatOn(); $data["created_at"] = $this->getCreatedAt(); $data["updated_at"] = $this->getUpdatedAt(); return $data; } }
<?php /** @Entity * @HasLifecycleCallbacks * @Table(name="user") */ namespace Entity; use Validation; use \DateTime; use \LogHelper;
<?php namespace Entity; use Validation; use \DateTime; use \LogHelper; /** @Entity * @HasLifecycleCallbacks * @Table(name="user") */