fosrestBundle和SonataUserBundle新领域系列化

时间:2015-09-28 22:01:10

标签: symfony fosuserbundle fosrestbundle jmsserializerbundle sonata-user-bundle

我使用在src / Application / Sonata / UserBundle下扩展的SonataUserBundle,我在src / Application / Sonata / UserBundle / Resources / config / doctrine / User.orm.xml中添加了一些额外的字段

<entity name="Application\Sonata\UserBundle\Entity\User" table="ez_user">

    <id name="id" column="id" type="integer">
        <generator strategy="AUTO" />
    </id>

    <many-to-many field="groups" target-entity="Application\Sonata\UserBundle\Entity\Group">
    <join-table name="ez_user_group">
        <join-columns>
            <join-column name="user_id" referenced-column-name="id"/>
        </join-columns>
        <inverse-join-columns>
            <join-column name="group_id" referenced-column-name="id"/>
        </inverse-join-columns>
    </join-table>
    </many-to-many>

    <many-to-one field="media" target-entity="Application\Sonata\MediaBundle\Entity\Media">
        <cascade>
            <cascade-all/>
        </cascade>
    </many-to-one>
    <field name="companyName" column="company_name" type="string" length="255" nullable="true" />

    <field name="companyPhone" column="company_phone" type="integer" nullable="true" />


</entity>

在src / Application / Sonata / UserBundle / Entity / User.php中添加了getter和setter 我的config.yml就像这样

fos_user:
     db_driver: orm
     firewall_name: main
     user_class: Application\Sonata\UserBundle\Entity\User
     group:
        group_class:   Application\Sonata\UserBundle\Entity\Group
        group_manager: sonata.user.orm.group_manager        

     service:
        user_manager: sonata.user.orm.user_manager     

sonata_user:
     security_acl: true
     manager_type: orm
     class:
         user: Application\Sonata\UserBundle\Entity\User
         group: Application\Sonata\UserBundle\Entity\Group

jms_serializer:
     metadata:
         directories:
             FOSUB:
                namespace_prefix: "FOS\\UserBundle"
                path: "%kernel.root_dir%/serializer/FOSUserBundle"

app / serializer / FOSUserBundle / Model.User.xml:

<serializer>
<class name="FOS\UserBundle\Model\User" exclusion-policy="all" xml-root-name="user">

    <property name="username"            type="string"   expose="true" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="usernameCanonical"   type="string"   expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
    <property name="email"               type="string"   expose="true" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="emailCanonical"      type="string"   expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
    <property name="enabled"             type="boolean"  expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="plainPassword"       type="string"   expose="false" since-version="1.0" groups="sonata_api_write" />
    <property name="lastLogin"           type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
    <property name="locked"              type="boolean"  expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="expired"             type="boolean"  expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="expiresAt"           type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="confirmationToken"   type="string"   expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
    <property name="passwordRequestedAt" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="roles"               type="array"    expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="credentialsExpired"  type="boolean"  expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="credentialsExpireAt" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="gender"              expose="false" />
    <property name="createdAt"           type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
    <property name="updatedAt"           type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />

</class>

配置中的jms部分是从api返回数据中隐藏一些属性,如(密码,盐等)

我的问题在于我的api a dan并未在SonataUserBundles中添加新字段(media,comanyName)

任何想法?

0 个答案:

没有答案