简体   繁体   中英

Symfony3 - Extend namespace

I have the following directory structure in my symfony3 structure:

src
    AppBundle
        AppBundle.php
        Entity
            User
                User.php
                UserRepository.php

On top of my User.php:

<?php

namespace AppBundle\Entity\User;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @ORM\Table(name="user")
 * @ORM\Entity(repositoryClass="AppBundle\Entity\User\UserRepository")
 */
class User implements UserInterface {

and it tells me:

undefined constant User

Is there any way extending the namespace?

Thanks and Greetings!

EDIT:

occurrence of "user":

security:
    providers:
        in_memory:
            memory:
                users:
                    admin:
                        password: admin
                        roles: 'ROLE_ADMIN'
        our_db_provider:
            entity:
                class: AppBundle:User
                property: username

    encoders:
        AppBundle\Entity\User\User:
            algorithm: bcrypt

AppBundle:User alias with your configuration resolves to AppBundle\\Entity\\User class, which obviously doesn't exist. Either use the full namespace AppBundle\\Entity\\User\\User or the AppBundle:User\\User alias.

This is how auto-mapping works. It looks for classes in the Entity folder in each bundle.

See the doctrine reference docs for more .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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