5

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?

David
  • 4,027
  • 10
  • 50
  • 102

4 Answers4

5

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

John Pancoast
  • 1,241
  • 16
  • 14
2

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)

Chopchop
  • 2,899
  • 18
  • 36
0

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

jamek
  • 792
  • 10
  • 20
  • After a rename occurs this error: 'Fatal error: Class 'Namespace\TestBundle\TestBundle' not found in C:\xampp\htdocs\ProjectX\app\AppKernel.php on line 21' – David Nov 05 '13 at 08:06
  • 2
    @David if you're new to Symfony2 you're better of removing and regenerating the bundle rather than hunting down invalid namespaces – Jovan Perovic Nov 05 '13 at 10:01
0

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
Community
  • 1
  • 1
matthew
  • 2,156
  • 5
  • 22
  • 38