简体   繁体   English

Symfony主义架构更新无法重新声明类

[英]Symfony Doctrine schema update cannot redeclare class

I am trying to debug the error "Fatal error: Cannot redeclare class Acme\\UserBundle\\Entity\\User in C:\\wamp\\www\\Symfony\\src\\Acme\\UserBundle\\entity\\User.php on line 15" in my command window when I want to create Mysql tables using the Doctrine command "php app/console doctrine:schema:update --force". 我正在尝试在命令窗口中调试错误“致命错误:无法在第15行的C:\\ wamp \\ www \\ Symfony \\ src \\ Acme \\ UserBundle \\ entity \\ User.php中重新声明Acme \\ UserBundle \\ Entity \\ User类”当我想使用Doctrine命令“ php app / console doctrine:schema:update --force”创建Mysql表时。

Here is the top of my entity code: 这是我的实体代码的顶部:

namespace Acme\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Acme\UserBundle\Entity\User
 *
 * @ORM\Table(name="acme_users")
 * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
 */
class User implements UserInterface, \Serializable
{    
 //...

To see where I could have double-declared my "User" class, I have renamed in into "User_alias" and cleared my cache (using the "php app/console cache:clear" command). 为了查看在哪里可以双重声明“ User”类,我将其重命名为“ User_alias”并清除了缓存(使用“ php app / console cache:clear”命令)。 The command window gives me then the error "The table with name 'basededonne.acme_users' already exists.'. However, I do not see this table in phpmyadmin. In addition, my browser gives me the error "FatalErrorException in User.php line 15: Compile Error: Cannot redeclare class Acme\\UserBundle\\Entity\\User_alias" (I did not have error in my browser when I used the "User" class). 命令窗口给我,然后出现错误“名称为'basededonne.acme_users'的表已经存在。”。但是,我在phpmyadmin中看不到该表。此外,我的浏览器在User.php行中给我显示错误“ FatalErrorException”。 15:编译错误:无法重新声明类Acme \\ UserBundle \\ Entity \\ User_alias“(使用“ User”类时在浏览器中没有错误)。

Could anyone give me some other options to explore to resolve this issue? 谁能给我一些其他选择来探索解决此问题的方法? There is a bigger picture that I am currently missing I guess. 我猜想我目前还没有一幅更大的图画。

In your User_alias.php you have class User definition. 在您的User_alias.php您可以找到class User定义class User

While you are trying to clear your cache in the warmup part of this command symfony generates some cache files based on your project files. 当您尝试在此命令的热身部分中清除高速缓存时,symfony会根据您的项目文件生成一些高速缓存文件。 And so after visiting class User in User.php it again visit class User in User_alias.php and throw an error. 因此,在访问User.php User类之后,它再次访问User_alias.php User类并引发错误。

Try to rename your class in User_alias.php and all will be working fine. 尝试在User_alias.php重命名您的类,然后一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM