Doctrine2 - class is not a valid entity or mapped super class
You are using a Doctrine\Common\Annotations\SimpleAnnotationReader
instead of a Doctrine\Common\Annotations\AnnotationReader
.
The SimpleAnnotationReader
works with default namespaces and reads annotations in format @Entity
, while the AnnotationReader
can use the imported classes and namespaces (via use
statement) and annotations such as @ORM\Entity
.
You can read more about that on the documentation.
Here's a fixed version of your test.php
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/entities/Users.php';
$paths = array(__DIR__ . '/entities');
$isDevMode = false;
$connectionParams = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => 'pass',
'dbname' => 'dbname',
);
$config = Setup::createConfiguration($isDevMode);
$driver = new AnnotationDriver(new AnnotationReader(), $paths);
// registering noop annotation autoloader - allow all annotations by default
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$em = EntityManager::create($connectionParams, $config);
$user = $em->find('Users', 5);
Symfony Doctrine ORM not a valid entity or mapped super class
May be datetime field has same name as function/implementation in doctrine, I have got same mistake by naming a table "condition" which may be condition function in MySql query
Related Topics
Send Zip File to Browser/Force Direct Download
How to Make a Chat Room Script with PHP
Object Copy Versus Clone in PHP
How to Tag a User in a Photo Using the Facebook Graph API
Error with .Htaccess and Mod_Rewrite
Php:Capturing the Command Output
Efficient Reloading Data/Pushing Data from Server to Client
Login Event Handling in Laravel 5
Php: How to Set Current Working Directory to Be Same as Directory Executing the Script
Checking If String Contains "Http://"
How to Use Etags in a PHP File
Facebook Like Custom Profile Url PHP
Setting Up PHPmailer with Office365 Smtp
How to Assign PHP Array Values to JavaScript Array
How to Auto-Resize a Div with CSS While Keeping Aspect Ratio