问题
when I tried to run the command php bin/console doctrine:generate:entities App:Center
in symfony 4.0.6 I get this error:
Can't find base path for "App\Entity\Center" (path: "/home/USER/foo/bar/src/Entity", destination: "/home/USER/foo/bar/src/Entity").
the Center
is my entity name!
how can I fix this?
回答1:
Doctrine developers are deprecating the generation commands for Symfony 4. The reason why it doesn't work for you is because the command is hardwired to find the destination directory under
projectRoot/src/{namespace}/{App}Bundle/Entity/{Center.php}
but the Symfony 4 directory structure is different than that, hence it cannot find it. If you are dead-set on using the command, you could probably extend it and create your own, in which you could change the destination path(s) for your entities. You can just skip the command part and generate getters and setters on your own.
Doctrine issue: https://github.com/doctrine/DoctrineBundle/issues/729
Symfony issue: https://github.com/symfony/symfony-docs/issues/8893
From the maintainers of Doctrine: https://github.com/doctrine/DoctrineBundle/pull/790
回答2:
So, from the various questions, I think your first problem is files permissions...
Meanwhile, you need to first correct your files permissions. Here is how to do it.
chown /home/alireza/Projects/www/ www-data:www-data /
find /home/alireza/Projects/www/ -type d -exec chmod 0755 "{}" \;
find /home/alireza/Projects/www/ -type f -exec chmod 0664 "{}" \;
find /home/alireza/Projects/www/ -type d -exec chmod g-s "{}" \;
find /home/alireza/Projects/www/ -type d -exec chmod g+s "{}" \;
As I assume that www/
is where all your projects are stored, I stopped the path at the www/
folder. It will thus correct files permissions for all of your projects.
Also, make sure to add your current user to the www-data
group.
usermod -a -G www-data user_name
Try this, and tell us if you still have your problem.
来源:https://stackoverflow.com/questions/49470932/generate-entity-in-symfony-4-methods