4
votes

I tried generate getters and setters in Symfony 3.0.1

when i run command

php bin/console doctrine:generate:entities VendorName/MyBundle/EntityName

i have error

Namespace "VendorName\MyBundle\EntityName" does not contain any mapped entities.

where is the mistake?

Edit-1: First generate entity with YAML format

Edit-2: I tried generate getters and setters for vendor bundle

Also i try with command php bin/console doctrine:generate:entities VendorNameMyBundle:EntityName and have another error:

Can't find base path for "VendorName\MyBundle\Entity\EntityName" (path: "/home/site/vendor/vendorname/mybundle/Entity", destination: "/home/site/vendor/vendorname/mybundle/Entity").  
3
did you first generate an entity classes with annotation mappings? (or YAML, XML mapping, whatever). Here the documentation.Federkun
First generate entity with YAML formatNeokortex
what's the path of your entity class? MyBundle\Entity\EntityName? Is VendorNameMyBundle a valid and registered bundle name?Federkun
VendorNameMyBundle is a valid and registered bundle nameNeokortex
Where is your EntityName.php file saved? What is your namespace value in EntityName.php? What is the class name in EntityName.php?Jan Rydrych

3 Answers

2
votes

As John Pancoast points out in his answer to a different question:

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 what exactly is needed to resolve the error message; You have to 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
     +--awesome-bundle
         |--Controller
         |--Entity

to:

vendor
 +--acme
     +--awesome-bundle
         +--Acme
             +--Bundle
                 +--AwesomeBundle
                     |--Controller
                     |--Entity

The following command will no longer throw an exception:

bin/console doctrine:generate:entities AwesomeBundle
0
votes

You have mistake in command, you trying to generate entities but you provide class name for one entity. Try the following for all entities:

php bin/console doctrine:generate:entities VendorName/MyBundle

or if you want just one entity:

php bin/console doctrine:generate:entity VendorName/MyBundle/EntityName
-1
votes

Symfony 3.22 with src/AppBundle/Entity/User.php

if you add new field using ORM

**/**
 * @ORM\Column(name="last_login", type="datetimetz")
 */
private $lastLogin;**

just use

use php bin/console doctrine:generate:entities AppBundle

it will check all your Entities r and update getters and setters

then use

php bin/console doctrine:schema:update to update your database

use

php bin/console doctrine:schema:update --force in PROD enviroment