Home >Backend Development >PHP Tutorial >How to use sonata-bundle in symfony2 to manage data information more conveniently?

How to use sonata-bundle in symfony2 to manage data information more conveniently?

WBOY
WBOYOriginal
2016-07-06 13:53:541058browse

I currently have 3 tables goods, category and brand. In the sonata background, I hope to display all category names and brand names in the product list. The following picture has detailed information:

How to use sonata-bundle in symfony2 to manage data information more conveniently?

How to use sonata-bundle in symfony2 to manage data information more conveniently?

As you can see from the picture above, the category of iphone6plus is mobile. Here I have defined the many-to-one relationship in the yml file. The display here is correct, but the brand.name is obviously wrong. The brand of iphone6plus It should be apple. I have a question here. I defined the many-to-one relationship twice in the goods.yml file. The second time I defined the goods and brand tables, they were not displayed correctly.

I want to manage product information more conveniently. I can browse product categories and brands on the same page. The same is true on the edit page. How should I achieve this? Here is my code block:

brand.orm.yml

<code>Application\Sonata\MallBundle\Entity\Brand:
    type: entity
    table: brand
    ...
oneToMany:
    goods:
        targetEntity: Goods
        mappedBy: brand
lifecycleCallbacks: {  }
</code>

goods.orm.yml

<code>Application\Sonata\MallBundle\Entity\Goods:
type: entity
table: goods
repositoryClass: Application\Sonata\MallBundle\Repository\GoodsRepository
...
manyToOne:
    category:
        targetEntity: Category
        inverseBy: goods
        joinColumn:
            name: category_id
            referencedColumnName: id
manyToOne:
    brand:
        targetEntity: Brand
        inverseBy: goods
        joinColumn:
            name: brand_id
            referencedColumnName: id
lifecycleCallbacks: {  }
</code>

category.orm.yml

<code>
Application\Sonata\MallBundle\Entity\Category:
type: entity
table: category
repositoryClass: Application\Sonata\MallBundle\Repository\CategoryRepository
...
oneToMany:
    goods:
        targetEntity: Goods
        mappedBy: category
lifecycleCallbacks: {  }</code>

Your suggestions are of great help to me.

Reply content:

I currently have 3 tables goods, category and brand. In the sonata background, I hope to display all category names and brand names in the product list. The following picture has detailed information:

How to use sonata-bundle in symfony2 to manage data information more conveniently?

How to use sonata-bundle in symfony2 to manage data information more conveniently?

As you can see from the picture above, the category of iphone6plus is mobile. Here I have defined the many-to-one relationship in the yml file. The display here is correct, but the brand.name is obviously wrong. The brand of iphone6plus It should be apple. I have a question here. I defined the many-to-one relationship twice in the goods.yml file. The second time I defined the goods and brand tables, they were not displayed correctly.

I want to manage product information more conveniently. I can browse product categories and brands on the same page. The same is true on the edit page. How should I achieve this? Here is my code block:

brand.orm.yml

<code>Application\Sonata\MallBundle\Entity\Brand:
    type: entity
    table: brand
    ...
oneToMany:
    goods:
        targetEntity: Goods
        mappedBy: brand
lifecycleCallbacks: {  }
</code>

goods.orm.yml

<code>Application\Sonata\MallBundle\Entity\Goods:
type: entity
table: goods
repositoryClass: Application\Sonata\MallBundle\Repository\GoodsRepository
...
manyToOne:
    category:
        targetEntity: Category
        inverseBy: goods
        joinColumn:
            name: category_id
            referencedColumnName: id
manyToOne:
    brand:
        targetEntity: Brand
        inverseBy: goods
        joinColumn:
            name: brand_id
            referencedColumnName: id
lifecycleCallbacks: {  }
</code>

category.orm.yml

<code>
Application\Sonata\MallBundle\Entity\Category:
type: entity
table: category
repositoryClass: Application\Sonata\MallBundle\Repository\CategoryRepository
...
oneToMany:
    goods:
        targetEntity: Goods
        mappedBy: category
lifecycleCallbacks: {  }</code>

Your suggestions are of great help to me.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn