Hi all,

I am trying to set up Doctrine 2 Orm for a self made MVC framework, but keep hitting the same error when trying to retrieve data:

Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class "App\models\menu" is not a valid entity or mapped super class.' in C:\wamp\www\framework\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\MappingException.php on line 336

I am using composers autoloader (PSR-4).

My setup for Doctrine is like this:

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use App\framework\core\database\entityInstance;

$paths      = array( '/app/models' );
$isDevMode  = false;

// the connection configuration
$dbParams = array(
    'driver'   => 'pdo_mysql',
    'user'     => 'root',
    'password' => '',
    'dbname'   => 'db_name',
);

$config         = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager  = EntityManager::create($dbParams, $config);

entityInstance::setManager( $entityManager );

I have a model that lookes like this:

namespace App\models;

use App\framework\core\database\entityInstance as ORM;


/**
 * @ORM\Entity
 * @ORM\Table(name="generator_menus")
 */
class menu 
{ 
     public static function test()
     {
        $db = ORM::getManager(); 

        $menu = $db->find('App\models\menu', 1 );

        die( var_dump( $menu ) );

        # $menu = $db->find('MyProject\Domain\User', $id);

        # $menu = $db->find('menu', 1);

        return $menu;
     }
}

I keep getting the same exceptions, and am obviously using/setting this up in a terrible way.

Anyone that know how to configure this?

Regards, Klemme

can you post your composer.json? Just want to see how you set up the autoload for PSR-4. For example, I have something like this for the MVC I co-wrote with Veedeoo

"autoload":{
            "psr-4":{
                        "System\\" : "vendor/geeglerapp/system/",
                        "App\\" : "vendor/geeglerapp/app/",
                        "Tbs\\": "vendor/tinybutstrong/"



                    }



}

keep in mind that some packages are 2 directories or more deeper inside the vendor directory.

Did you try typing this on your command prompt

dump-autoload -o

it is "o" and not zero.

Whenever you added or change namespaces on a file, you need to use the dump command.

just to add another hint. Normally, we we add packages from packagist.org through composer. We would look for the class needed to install or setup the package. In the case of Doctrine, the package wanted us to add this on the composer.json file inside the require block.

 "doctrine/orm": "*"

while on the front controller or bootstrap, they want us to have this

require_once "vendor/autoload.php";

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

the problem here is that we don't even know if the package is properly loaded or installed.

If you want you can experiment by opening

vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Setup.php

find the closing bracket of the method

public static function createConfiguration()
{
}

and then add

public static function testSetup()
{
    echo 'testing setup'.__CLASS__.'<br/>';
}

open your command prompt and then type

composer dump-autoload -o

hit enter;

open your bootstrap, and then call the static test method

setup::testSetup();

good luck...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.