我正在尝试在我的Symfony2应用程序中安装SonataAdminBundle,除了UserBundle之外似乎工作正常。它未在数据库中更新。 当我这样做时:
php app/console doctrine:mapping:info
它让我接下来:
[OK] HoHa\UserBundle\Entity\User
[OK] Sonata\UserBundle\Entity\BaseUser
[OK] Sonata\UserBundle\Entity\BaseGroup
是的,它被映射了。但是没有创建字段(除了id)。 看看我的实体User.php:
<?php
namespace HoHa\UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
#I've also tried: use Sonata\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
为什么在更新数据库时不会扩展用户? FOSUserBundle显示登录和注册页面,Sonata也显示登录页面。
当我这样做时:
$ php app/console doctrine:schema:update --force
我明白了:
Nothing to update - your database is already in sync with the current entity metadata.
这是我的app / config / config.yml文件:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: @HoHaHomeBundle/Resources/config/admin.yml }
framework:
#esi: ~
translator: ~
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_proxies: ~
session: ~
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.jar
yui_js:
'jar': %kernel.root_dir%/Resources/java/yuicompressor.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
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: %kernel.root_dir%/data/data.db3
# path: %database_path%
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: %kernel.debug%
#auto_mapping: true
entity_managers:
default:
mappings:
HoHaUserBundle: ~
SonataUserBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
#sonata.admin_doctrine_orm.block.audit:
# contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
# Some specific block from the SonataMediaBundle
#sonata.media.block.media:
#sonata.media.block.gallery:
#sonata.media.block.feature_media:
fos_user:
db_driver: orm
firewall_name: main
user_class: HoHa\UserBundle\Entity\User
group:
group_class: HoHa\UserBundle\Entity\Group
sonata_admin:
templates:
dashboard: SonataAdminBundle:Core:dashboard.html.twig
和我的app / config / security.yml文件:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
SONATA:
- ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are using acl then this line must be commented
providers:
in_memory:
memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
fos_userbundle:
id: fos_user.user_manager
#id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# -> custom firewall for the admin area of the URL
admin:
pattern: /admin(.*)
context: user
form_login:
provider: fos_userbundle
login_path: /admin/login
use_forward: false
check_path: /admin/login_check
failure_path: null
logout:
path: /admin/logout
anonymous: true
# -> end custom configuration
# defaut login area for standard users
# This firewall is used to handle the public login area
# This part is handled by the FOS User Bundle
main:
pattern: .*
context: user
form_login:
provider: fos_userbundle
login_path: /login
use_forward: false
check_path: /login_check
failure_path: null
logout: true
anonymous: true
login:
pattern: ^/demo/secured/login$
security: false
secured_area:
pattern: ^/demo/secured/
form_login:
check_path: _security_check
login_path: _demo_login
logout:
path: _demo_logout
target: _demo
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
# URL of FOSUserBundle which need to be available to anonymous users
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
# Admin login page needs to be access without credential
- { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
# Secured part of the site
# This config requires being logged for the whole site and having the admin role for the admin part.
# Change these rules to adapt them to your needs
- { path: ^/admin/, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
- { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
文件app / logs / dev.log为我提供了下一个:
[2013-08-26 17:40:27] doctrine.DEBUG: SELECT TABLE_NAME AS `Table`, NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, SEQ_IN_INDEX AS Seq_in_index, COLUMN_NAME AS Column_Name, COLLATION AS Collation, CARDINALITY AS Cardinality, SUB_PART AS Sub_Part, PACKED AS Packed, NULLABLE AS `Null`, INDEX_TYPE AS Index_Type, COMMENT AS Comment FROM information_schema.STATISTICS WHERE TABLE_NAME = 'fos_user' AND TABLE_SCHEMA = 'hoha' [] []
答案 0 :(得分:1)
我知道,老问题,但我只是遇到了同样的问题。 对我来说,解决方案是将以下内容添加到Appkernel包中:
new Sonata \ EasyExtendsBundle \ SonataEasyExtendsBundle(),
新的Sonata \ UserBundle \ SonataUserBundle(&#39; FOSUserBundle&#39;),//&#39; FOSUserBundle&#39;是可选的
之后我遇到了一个新问题,我得到了一个[Doctrine \ DBAL \ DBALException]未知列类型&#34; json&#34;请求.... 这在config.yml
中由以下修复教义:
dbal:
types:
json: Sonata\Doctrine\Types\JsonType
希望这有助于任何人。
答案 1 :(得分:0)
在app/config/config.yml
中,尝试将FOSUserBundle用户类设置为您自己的类。
fos_user:
<...>
user_class: Acme\UserBundle\Entity\User # Your class here
答案 2 :(得分:0)
在我的例子中,xml优先于ApplicationSonataUserBundle中的注释。
我通过Resources / config / doctrine.bak重命名了Resources / config / doctrine,ApplicationSonataUserBundle中的User.php现在是我的实体。