Doctrine 2.2에 이상한 문제가 있습니다. 나는 데이터베이스에 새로운 항목을 넣으려고했는데 다음과 같은 문제에 직면했다. 그것은 무엇을 의미하며 어떻게 해결할 수 있습니까?Doctrine 2.2에서 캐치되지 않는 예외가 데이터베이스에 새로운 항목을 삽입하는 중
Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class Model\User is not a valid entity or mapped super class.' in C:\xampp\htdocs\www\DoctrineExplained\DoctrineORM\Doctrine\ORM\Mapping\MappingException.php:147
Stack trace:
#0 C:\xampp\htdocs\www\DoctrineExplained\DoctrineORM\Doctrine\ORM\Mapping\Driver\AnnotationDriver.php(166): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass('Model\User')
#1 C:\xampp\htdocs\www\DoctrineExplained\DoctrineORM\Doctrine\ORM\Mapping\ClassMetadataFactory.php(293): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('Model\User', Object(Doctrine\ORM\Mapping\ClassMetadata))
#2 C:\xampp\htdocs\www\DoctrineExplained\DoctrineORM\Doctrine\ORM\Mapping\ClassMetadataFactory.php(178): Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('Model\User')
#3 C:\xampp\htdocs\www\DoctrineExplained\DoctrineORM\Doctrine\ORM\EntityManager.php(271): Doctrine\ORM\Mapping\ClassMetadataFactory->getMe in C:\xampp\htdocs\www\DoctrineExplained\DoctrineORM\Doctrine\ORM\Mapping\MappingException.php on line 147
내 프로젝트 디렉토리 구조는 다음과 같다 :
./test
DoctrineORM/
DoctrineORM/빈
DoctrineORM/빈/교리
모델/
모델/
test.php
그리고 마지막으로, 사람들은 테스트에 내 코드는 User.php. ph 및 모델/User.php
012 3,516,--- Model/User.php ---
<?php
// Model File model/User.php
namespace Model;
/** @Entity @Table(name="users") */
class User
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/** @Column(type="string", length=50) */
public $name;
/** @Column(type="integer", length=50) */
public $age;
}
?>
그리고 마지막 코드는 test.php
<?php
//// test.php
require 'DoctrineORM/Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', 'DoctrineORM');
$classLoader->register();
$classloader = new \Doctrine\Common\ClassLoader('model', __DIR__);
$classloader->register();
$config = new \Doctrine\ORM\Configuration();
$cache = new \Doctrine\Common\Cache\ArrayCache();
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('model');
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir('proxies');
$config->setProxyNamespace('proxies');
$config->setAutoGenerateProxyClasses(true);
$config->getAutoGenerateProxyClasses();
$connectionOptions = array(
'driver' => 'pdo_mysql',
'dbname' => 'test',
'user' => 'root',
'password' => '0000'
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
// insert a new User to DB
$user = new model\User();
$user->name = 'lorem impum user';
$user->age = 55;
$em->persist($user);
$em->flush();
Doctrine 2 CLI 도구로 orm : validate-schema를 실행 해보십시오. 출력은 무엇입니까? 그것을 확인합니까? –
미안 해요, 리눅스에서 이것을 개발하지 않습니다. (windows에서) 어떻게하면 윈도우에서 실행할 수 있습니까? –
다음 지침을 따르십시오. http://codeutopia.net/blog/2008/07/28/setting-up-command-line-php-on-windows/ - php 명령을 설정 한 후에는 다음을 수행 할 수 있습니다. doctrine 도구를 실행하십시오 –