我有两张桌子A(Utenti)e B(Dispositivi);在B上有一个A的外键(一个Utente->许多Dispositivi)。我使用symfony管理生成器。我是否可以为每个Utente生成一个链接,该链接会在Dispositivi视图中列出我所有相关的Dispositivi。这有可能吗?
的schema.yml
Dispositivi:
connection: doctrine
tableName: dispositivi
columns:
id_dispositivo:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
device_id:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
tipo:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
utente_fk:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Utenti:
local: utente_fk
foreign: id_utente
type: one
Utenti:
connection: doctrine
tableName: utenti
columns:
id_utente:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
username:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
password:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
tipo:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Dispositivi:
local: id_utente
foreign: utente_fk
type: many
Servizi:
local: id_utente
foreign: utente_fk
type: many
答案 0 :(得分:1)
以下是对学说代码的一个很好的参考:
http://redotheweb.com/2008/07/08/comparing-propel-doctrine-and-sfpropelfinder/ (特别是如果用来推动。)
首先,在generator.yml文件中添加一个部分。
然后做这样的事情:
<?php
$dispositivis = $utente->Dispositivis;
?>
<?php foreach ($dispositivis as $d): ?>
<?php echo link_to($d->getTipo(), 'module_name/action_name?id='. $d->getIdDispositivo()) ?><br />
<?php endforeach ?>