2013-08-25 52 views
2

我想在我的Symfony2應用程序中安裝SonataAdminBundle,似乎除UserBundle以外工作正常。它不會在數據庫中更新。 當我做:數據庫不更新與FOSUserBundle

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. 

這是我的應用程序/配置/ 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 

和我的應用程序/配置/ 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 /日誌/ 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

在你app/config/config.yml,嘗試FOSUserBundle用戶類型設置爲你自己的。

fos_user: 
    <...> 
    user_class: Acme\UserBundle\Entity\User # Your class here 

來源:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md#step-5-configure-the-fosuserbundle

+0

我已經設置它。 – Manolo

+0

其實,我們正在擴展'FOS \ UserBundle \ Entity \ User作爲BaseUser'。也許這會有所幫助。另外,嘗試使用'SonataEasyExtendsBundle'命令來擴展FOSUserBundle。另外,請先嚐試擴展「Sonata \ UserBundle \ Model \ User」。當這個工作,移動到FOSUserBundle – TautrimasPajarskas

+0

那麼,你可以看到「使用FOS \ UserBundle \ Model \ User作爲BaseUser;」我試過「使用Sonata \ UserBundle \ Model \ User作爲BaseUser;」。通過使用SonataEasyExtendsBundle擴展FOSUserBundle?我不想更改第三方軟件包,因爲它應該可以將它們擴展到您自己的軟件包中。 – Manolo

1

我知道,老的問題,但是我只是有這個同樣的問題。 對於我的解決辦法是添加以下束Appkernel:

新索納塔\ EasyExtendsBundle \ SonataEasyExtendsBundle(),

新索納塔\ UserBundle \ SonataUserBundle( 'FOSUserBundle'),//將 'FOSUserBundle' 是可選

之後,我遇到了一個新的問題,我得到了[學說\ DBAL \ DBALException]未知列型「JSON」要求.... 這是固定在config.yml

以下

學說:

dbal:  
    types: 
     json: Sonata\Doctrine\Types\JsonType 

希望這可以幫助任何人。

0

在我的情況下,XML具有優先於ApplicationSonataUserBundle中的註釋。

我通過Resources/config/doctrine.bak更名爲Resources/config/doctrine,ApplicationSonataUserBundle中的User.php現在是我的實體。