• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

在 symfony2 中使用 sonata-bundle,如何更加便捷地管理数据信息?

php 搞代码 3年前 (2022-01-23) 19次浏览 已收录 0个评论
文章目录[隐藏]

<body>

我目前有3张表goodscategory and brand,在sonata后台中,我希望可以把类别名称和品牌名称全部显示在货品列表,下图有详细的信息:

从上图可以看出,iphone6plus的类别是mobile,这里我在yml文件中定义了many-to-one的关系,这里显示是正确的,但是brand.name很明显错了,iphone6plus的品牌应该是apple,这里我有疑问,我我在 goods.yml 文件中定义了两次many-to-one关系,第二次定义的是goodsbrand表,并没有正确显示。

我想更便捷地管理货品信息,在同一页面,浏览商品类别和品牌,在编辑页面同理,我应该如何实现呢?下面是我的代码块:

brand.orm.yml

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

goods.orm.yml

<code>Application\Sonata\MallBundle\Entity\Goods:type: entitytable: goodsrepositoryClass: Application\Sonata\MallBundle\Repository\GoodsRepository...manyToOne:    category:        targetEntity: Category        inverseBy: goods        joinColumn:            name: category_id            referencedColumnName: idmanyToOne:    brand:  <i>本文@来#源gaodai$ma#com搞$$代**码网</i><strong>搞代gaodaima码</strong>      targetEntity: Brand        inverseBy: goods        joinColumn:            name: brand_id            referencedColumnName: idlifecycleCallbacks: {  }</code>

category.orm.yml

<code>Application\Sonata\MallBundle\Entity\Category:type: entitytable: categoryrepositoryClass: Application\Sonata\MallBundle\Repository\CategoryRepository...oneToMany:    goods:        targetEntity: Goods        mappedBy: categorylifecycleCallbacks: {  }</code>

您的建议,对我来说是莫大的帮助。

回复内容:

<body>

我目前有3张表goodscategory and brand,在sonata后台中,我希望可以把类别名称和品牌名称全部显示在货品列表,下图有详细的信息:

从上图可以看出,iphone6plus的类别是mobile,这里我在yml文件中定义了many-to-one的关系,这里显示是正确的,但是brand.name很明显错了,iphone6plus的品牌应该是apple,这里我有疑问,我我在 goods.yml 文件中定义了两次many-to-one关系,第二次定义的是goodsbrand表,并没有正确显示。

我想更便捷地管理货品信息,在同一页面,浏览商品类别和品牌,在编辑页面同理,我应该如何实现呢?下面是我的代码块:

brand.orm.yml

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

goods.orm.yml

<code>Application\Sonata\MallBundle\Entity\Goods:type: entitytable: goodsrepositoryClass: Application\Sonata\MallBundle\Repository\GoodsRepository...manyToOne:    category:        targetEntity: Category        inverseBy: goods        joinColumn:            name: category_id            referencedColumnName: idmanyToOne:    brand:        targetEntity: Brand        inverseBy: goods        joinColumn:            name: brand_id            referencedColumnName: idlifecycleCallbacks: {  }</code>

category.orm.yml

<code>Application\Sonata\MallBundle\Entity\Category:type: entitytable: categoryrepositoryClass: Application\Sonata\MallBundle\Repository\CategoryRepository...oneToMany:    goods:        targetEntity: Goods        mappedBy: categorylifecycleCallbacks: {  }</code>

您的建议,对我来说是莫大的帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:在 symfony2 中使用 sonata-bundle,如何更加便捷地管理数据信息?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址