产品咨询价格和尺寸

时间:2016-01-09 16:19:26

标签: php symfony doctrine

我有一张包含此类产品的表格:

<?php

/** some code */

class Catalogo
{
    private $id;

    private $product;

    /**
    * @ORM\OneToMany(targetEntity="Unidades", mappedBy="catalogo", cascade={"persist", "remove"})
    */
protected $unidades;
}

(显然我删除了不必要的注释和代码)

在产品和价格中包含上述措施的其他相关表格进行交易。

<?php

class Unidades
{
    private $id;

    private $medida;

    private $precio;

    /**
     * @ORM\ManyToOne(targetEntity="Catalogo", inversedBy="unidades", cascade = {"persist"})
     * @ORM\JoinColumn(name="catalogo_id", referencedColumnName="id")
     */
    protected $catalogo;
}

我必须为所有产品提供相应的措施和价格,但不是如何。我必须做这样的事情:

product1: 
        measure       price
        measure       price
        measure       price

product2: 
        measure       price
        measure       price
        measure       price

productN: 
        measure       price
        measure       price
        measure       price

使其更加真实:

sand: 
            5 KG          $5
            10 KG         $10
            20 KG         $20

cement:
            5 KG          $7
            10 KG         $10
            20 KG         $12
你帮我吗?感谢

1 个答案:

答案 0 :(得分:0)

你应该可以使用getter

$em = $this->getDoctrine()->getEntityManager();
$catalog = $em->getRepository()->findAll() 

foreach($catalog as $product) {
  $price       = $product->getPrecio();
  $measurement = $product->getMedida();
}

我已经添加了上面的循环,但您应该能够将catalog变量传递到您的视图并在那里循环播放。

http://symfony.com/doc/current/book/doctrine.html