I have a clean install of just Doctrine ORM
Please help I get MappingException for a Product class all the time
<?php
namespace src;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product{
/**
* @ORM\Column(type="integer", length = 5)
* @ORM\Id
* @ORM\GenerateValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=2, name="product_code")
*/
protected $code;
/**
* @ORM\Column(type="string", length=10, name="product_name")
*/
protected $name;
}
I have a regular bootstrap file
<?php
// bootstrap.php
require_once "vendor/autoload.php";
require_once "src/Product.php";
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array(__DIR__."/src");
$isDevMode = true;
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => '',
'dbname' => 'myDbName',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
$theProduct = $entityManager->find("Product", 500);
And I have a composer with
{
"require": {
"doctrine/orm": "v2.5.10"
},
"autoload": {
"psr-4": {
"src\\": "src/"
}
}
}
I am running bootstrap.php
Whatever I do I always get Fatal error: Uncaught Doctrine\Common\Persistence\Mapping\MappingException: Class 'Product' does not exist in D:\projects\pp\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php on line 96
__DIR__."/src"
? Did you print that path and check if everything's correct? Is the autoloader configured correctly? – ccKep"autoload": {"psr-4": {"src\\": "src/"}}
to your composer.json (usingsrc
as a namespace is quite unusual though) – ccKepentity
insidesrc
which was namespacedsrc\entity
but I removed everything to get clear understanding of what is going on, if by unusual you mean folder structure. – user3410843