Symfony1 基于关系的外场分配
我有以下模式:Symfony1 基于关系的外场分配,symfony1,symfony-1.4,Symfony1,Symfony 1.4,我有以下模式: catalogue: actAs: [Timestampable, Sortable] columns: id: type: integer(2) primary: true autoincrement: true catalogue_name: type: varchar(255) relations: catalogue: class: Product ref
catalogue:
actAs: [Timestampable, Sortable]
columns:
id:
type: integer(2)
primary: true
autoincrement: true
catalogue_name:
type: varchar(255)
relations:
catalogue:
class: Product
refClass: ProductPrices
local: catalogue_id
foreign: product_id
ProductPrices:
actAs: [Timestampable]
columns:
product_id: { type: integer(4)}
catalogue_id: { type: integer(2) }
price: { type:real }
relations:
Product: { local: product_id, foreign: id }
catalogue: { local: catalogue_id, foreign: id }
indexes:
unique_price: { fields: [catalogue_id, product_id], type: unique }
Product:
actAs: [Timestampable]
columns:
id:
type: integer(4)
primary: true
autoincrement: true
product_code:
type: varchar(10)
product_desc:
type: varchar(255)
created_at:
type: timestamp
relations:
catalogue:
class: catalogue
refClass: ProductPrices
local: product_id
foreign: catalogue_id
现在这是产品
和目录
我想做的是,在HTML表格中显示每个目录及其产品
我已经创建了一个概要和一个条令查询:
public static function getPricingTable()
{
$q = Doctrine_Query::create()
->from('ProductPrices p');
return $q->execute();
}
现在,我唯一的问题是显示目录和产品,即
目录1
* Product 1
* Product 2
* Product 3
目录2
* Product 1
感谢所有帮助如果您想获得目录的所有产品,只需使用目录实例的getProduct()方法即可 例如,如果要获取所有产品的所有目录:
$catalogues = Doctrine::getTable('catalogue')->findAll();
foreach($catalogues as $catalogue){
//$catalogue is an instance
echo $catalogue->getCatalogueName()
//you've got all products from a catalogue instance
foreach($catalogue->getProduct() as $product){
echo $product->getProductDesc();
}
}