gpt4 book ai didi

php - ClassNotFoundException : Attempted to load class "FOSUserBundle" from namespace "FOS\UserBundle"

转载 作者:行者123 更新时间:2023-12-04 14:25:38 25 4
gpt4 key购买 nike

(在 Windows 10 上使用 WampServer。)

我按照官方文档在 Symfony 上安装 Sonata User Bundle。

我收到以下错误消息

(1/1) ClassNotFoundException Attempted to load class "FOSUserBundle" from namespace "FOS\UserBundle". Did you forget a "use" statement for another namespace?



AppKernel.php
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
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 Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),

new Sonata\CoreBundle\SonataCoreBundle(),

//Added following https://sonata-project.org/bundles/admin/3-x/doc/getting_started/installation.html
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),

//Added following https://sonata-project.org/bundles/easy-extends/2-x/doc/reference/installation.html
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),

//Added following https://sonata-project.org/bundles/user/3-x/doc/reference/installation.html
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),


];

if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();

if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}

return $bundles;
}

public function getRootDir()
{
return __DIR__;
}

public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}

public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}

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

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en

framework:
#esi: ~
#translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: '%locale%'
trusted_hosts: ~
session:
# https://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true

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

# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
types:
json: Sonata\Doctrine\Types\JsonType

orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
entity_managers:
default:
mappings:
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
FOSUserBundle: ~ # If SonataUserBundle extends it

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

#Sonata
sonata_core:
form_type: horizontal

sonata_user:
security_acl: true
manager_type: orm # can be orm or mongodb

sonata_block:
default_contexts: [cms]
blocks:
# enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
#...
sonata.user.block.menu: # used to display the menu in profile pages
sonata.user.block.account: # used to display menu option (login option)
sonata.block.service.text: # used to if you plan to use Sonata user routes

#FOSUser
fos_user:
db_driver: orm # can be orm or odm
firewall_name: main
user_class: Sonata\UserBundle\Entity\BaseUser

group:
group_class: Sonata\UserBundle\Entity\BaseGroup
group_manager: sonata.user.orm.group_manager # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb)

service:
user_manager: sonata.user.orm.user_manager # If you're using doctrine orm (use sonata.user.mongodb.user_manager for mongodb)

路由.yml
login_view:
path: '/login/'
defaults: { _controller: AppBundle:Login:view }

singlesingon_view:
path: '/authentication/singlesignon/'
defaults: { _controller: AppBundle:AuthenticationSingleSignOn:view }

singlesingout_view:
path: '/authentication/singlesignout/'
defaults: { _controller: AppBundle:AuthenticationSingleSignOut:view }

app:
resource: '@AppBundle/Controller/'
type: annotation

admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin

sonata_user_admin_security:
resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
prefix: /admin

sonata_user_admin_resetting:
resource: '@SonataUserBundle/Resources/config/routing/admin_resetting.xml'
prefix: /admin/resetting

当我到达从运行开始的第 2.5 步时
php bin/console sonata:easy-extends:generate SonataUserBundle -d src

我得到

Fatal error: Class 'FOS\UserBundle\FOSUserBundle' not found.



根据评论中的要求:composer.json 的自动加载部分
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},

最佳答案

在 composer.json 中

 "autoload": {
"psr-0": {
"": "src/",
"Application": "app/"
}
},

比更新 Composer :
composer update

如果这不起作用,请尝试通过以下命令修复捆绑包:
php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle

扩展基本用户 FosUser :
class Myusers extends BaseUser
{
}

在 config.yml
fos_user:
user_class: MyBundle\Entity\Myusers

关于php - ClassNotFoundException : Attempted to load class "FOSUserBundle" from namespace "FOS\UserBundle",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45630629/

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