gpt4 book ai didi

Symfony 2.5.5 & FOSUserBundle : the class . ..在链配置的命名空间中找不到

转载 作者:行者123 更新时间:2023-12-02 18:24:14 31 4
gpt4 key购买 nike

最近,我开始使用 Symfony2。现在我想向我的网站添加用户管理引擎。

但是我遇到了一个问题。这就是我正在做的事情:

  1. 在创建/安装基本 Symfony2 项目方面:

    $ composer create-project symfony/framework-standard-edition path/ "2.5.*"
    $ mv path/* ./
    $ rm -r path/
  2. 好的,Symfony 2.5.5 就讲这么多。接下来,下载 FOSUserBundle 并创建自定义 bundle :

    $ composer require friendsofsymfony/user-bundle '~2.0@dev'
    $ php app/console generate:bundle --namespace=Meiblorn/CoreBundle --format=yml
  3. 在 Meiblorn\CoreBundle\Framework\Domain 命名空间中创建 User 类

    /**
    * User: Meiblorn
    * Date: 15/10/14
    * Time: 20:17
    */

    namespace Meiblorn\CoreBundle\Framework\Domain;

    use FOS\UserBundle\Model\User as FOSUserBundleUser;
    use Doctrine\ORM\Mapping as ORM;

    /**
    * @ORM\Entity
    * @ORM\Table(
    * name = "users"
    * )
    */
    class User extends FOSUserBundleUser {

    /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    protected $id;

    public function __construct() {
    parent::__construct();
    // your own logic
    }

    }

    ?>
  4. 配置 security.yml 和 config.yml。最后,我得到了这个:

    AppKernel.php

    $bundles = array(
    new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
    new Symfony\Bundle\SecurityBundle\SecurityBundle(),
    new Symfony\Bundle\TwigBundle\TwigBundle(),
    new Symfony\Bundle\MonologBundle\MonologBundle(),
    new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
    new Symfony\Bundle\AsseticBundle\AsseticBundle(),
    new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),

    new FOS\UserBundle\FOSUserBundle(),

    new Meiblorn\CoreBundle\MeiblornCoreBundle(),
    );

    config.yml

    imports:
    - { resource: parameters.yml }
    - { resource: security.yml }

    framework:
    #esi: ~
    translator: { fallback: "%locale%" }
    secret: "%secret%"
    router:
    resource: "%kernel.root_dir%/config/routing.yml"
    strict_requirements: ~
    form: ~
    csrf_protection: ~
    validation: { enable_annotations: true }
    templating:
    engines: ['twig']
    #assets_version: SomeVersionScheme
    default_locale: "%locale%"
    trusted_hosts: ~
    trusted_proxies: ~
    session:
    # handler_id set to null will use default session handler from php.ini
    handler_id: ~
    fragments: ~
    http_method_override: true

    # Twig Configuration
    twig:
    debug: "%kernel.debug%"
    strict_variables: "%kernel.debug%"

    # Assetic Configuration
    assetic:
    debug: "%kernel.debug%"
    use_controller: false
    bundles: [ ]
    #java: /usr/bin/java
    filters:
    cssrewrite: ~
    #closure:
    # jar: "%kernel.root_dir%/Resources/java/compiler.jar"
    #yui_css:
    # jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

    # Doctrine Configuration
    doctrine:
    dbal:
    driver: "%database_driver%"
    host: "%database_host%"
    port: "%database_port%"
    dbname: "%database_name%"
    user: "%database_user%"
    password: "%database_password%"
    charset: UTF8
    orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true

    # Swiftmailer Configuration
    swiftmailer:
    transport: "%mailer_transport%"
    host: "%mailer_host%"
    username: "%mailer_user%"
    password: "%mailer_password%"
    spool: { type: memory }

    fos_user:
    db_driver: orm
    firewall_name: prod
    user_class: Meiblorn\CoreBundle\Framework\Domain\User

    安全.yml

    security:
    encoders:
    FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
    ROLE_ADMIN: ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
    fos_userbundle:
    id: fos_user.user_provider.username

    firewalls:
    prod:
    pattern: ^/
    form_login:
    provider: fos_userbundle
    csrf_provider: form.csrf_provider
    logout: true
    anonymous: true
    dev:
    pattern: ^/(_(profiler|wdt)|css|images|js)/
    security: false

    access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

这就是问题

In browser:  http://localhost/test.meiblorn.com/web/app_dev.php/

MappingException: The class 'Meiblorn\CoreBundle\Framework\Domain\User' was not found in the chain configured namespaces FOS\UserBundle\Model
in /Library/WebServer/Documents/test.meiblorn.com/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 37
at MappingException::classNotFoundInNamespaces('Meiblorn\CoreBundle\Framework\Domain\User', array('FOS\UserBundle\Model')) in /Library/WebServer/Documents/test.meiblorn.com/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php line 113
at MappingDriverChain->loadMetadataForClass('Meiblorn\CoreBundle\Framework\Domain\User', object(ClassMetadata)) in /Library/WebServer/Documents/test.meiblorn.com/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php line 117
at ClassMetadataFactory->doLoadMetadata(object(ClassMetadata), object(ClassMetadata), false, array()) in /Library/WebServer/Documents/test.meiblorn.com/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php line 318

此外,在调用 Doctrine:schema:update 时,Doctrine 不会为此映射创建表

请帮我解决此异常

<小时/>

更新!如何修复

我的命名空间的最终配置

orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
FOSUserBundle: ~
MeiblornCoreBundle:
type: annotation
dir: %kernel.root_dir%/../src/Meiblorn/CoreBundle/Framework/Entity
prefix: Meiblorn\CoreBundle\Framework\Entity
# alias: MyModels
# is_bundle: true

最佳答案

首先,您需要在您的composer.js中配置psr-4自动加载,例如

"autoload": {
"psr-4": {
"Meiblorn\\CoreBundle\\": "src/Meiblorn/CoreBundle/"
}
},

然后调用composer dumpautoload

其次,我相信 Doctrine 希望实体位于文件夹 Entity/ 中,因此请尝试移动模型:src/Meiblorn/CoreBundle/Framework/Domain/User.phpsrc/Meiborn/CoreBundle/Entity/User.phpHow do I change symfony 2 doctrine mapper to use my custom directory instead of my Entity Directory under the bundle

关于Symfony 2.5.5 & FOSUserBundle : the class . ..在链配置的命名空间中找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26405237/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com