Generate entity in symfony 4 (methods)

柔情痞子 提交于 2020-01-16 18:46:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!