5
votes

I'm using Symfony2 and want to generate getters and setters for the entities by running:

$ php app/console doctrine:generate:entities TestBundle

enter image description here

The Console returns me the following message:

[RuntimeException] Can't find base path for "TestBundle" (path: "C:\xampp\htdocs\ProjectX\src\Namespace\TestBundle", destination: "C:/xampp/htdocs/ProjectX/src/Namespace/TestBundle").

The Bundle exists at this location: C:\xampp\htdocs\ProjectX\src\Namespace\TestBundle

Whats wrong?

4

4 Answers

5
votes

Just to add something else in case others reach this. I had an issue causing the same error but it was due to my entities living in a codebase that used PSR-4. Doctrine does not support PSR-4 when doing anything with code generation. It has to do with how they map class namespaces to filesystem paths and how PSR-4 allows class/namespace paths that don't directly map to the filesystem.

https://github.com/doctrine/DoctrineBundle/issues/282

2
votes

I had this probleme caused by some issue with lower case /upper case in my bundle directory. It souldn't be an issue under windows, but the php function str_replace is case sensitive an generate the error

//Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory

private function getBasePathForClass($name, $namespace, $path)
    {
        $namespace = str_replace('\\', '/', $namespace);
        $search = str_replace('\\', '/', $path);
        $destination = str_replace('/' . $namespace, '', $search, $c);

        if ($c != 1) {
            throw new \RuntimeException(sprintf('Can\'t find base path for "%s" (path: "%s", destination: "%s").', $name, $path, $destination));
        }

        return $destination;
    }

Doctrine can't re-create the class path based on the namespace : So it means your namespace or your folder is wrong (check case)

0
votes

Name of your Bundle php file is wrong change from TestBundle.php to NamespaceTestBundle.php in path: C:/xampp/htdocs/ProjectX/src/Namespace/TestBundle/

0
votes

John Pancoast's answer is correct.

Just to add something else in case others reach this. I had an issue causing the same error but it was due to my entities living in a codebase that used PSR-4. Doctrine does not support PSR-4 when doing anything with code generation. It has to do with how they map class namespaces to filesystem paths and how PSR-4 allows class/namespace paths that don't directly map to the filesystem.

https://github.com/doctrine/DoctrineBundle/issues/282

To clarify exactly what is needed to resolve the error message; edit your bundle's composer.json file, and also change the bundle's folder structure.

in composer.json change psr-4 to psr-0:

"autoload": {
    "psr-4": { "Acme\\Bundle\\AwesomeBundle\\": "" }
},

to:

"autoload": {
    "psr-0": { "Acme\\Bundle\\AwesomeBundle\\": "" }
},

Change bundle's folder structure from:

vendor
 +--acme
     +--awsome-bundle
         |--Controller
         |--Entity

to:

vendor
 +--acme
     +--awsome-bundle
         +--Acme
             +--Bundle
                 +--AwsomeBundle
                     |--Controller
                     |--Entity

The following command wil no longer throw an exception:

bin/console doctrine:generate:entities AwesomeBundle