我想設置嵌套embedRelation()實例的一些條件語句,並且無法找到一種方法來通過第二個embedRelation 。Symfony:embedRelation()嵌套多層次的關係的控制選項
我有一個「測量 - >頁面 - >問題」表關係,我希望能夠選擇是否顯示問題表。例如,假設我有兩個「成功」頁面,page1Success.php和page2Success.php。在頁面1上,我想顯示「測量 - >頁面 - >問題」,並在頁面2上,我想顯示「測量 - >頁面」,但我需要一種方法將「選項」傳遞給PageForm .class.php文件做出這樣的決定。我的actions.class.php文件中有這樣的事情:
// actions.class.php
$this->form = new measureForm($measure, array('option'=>$option));
傳遞一個選項「頁面」,而是傳遞一個選項,通過「頁」到「問題」不工作。
我measureForm.class.php文件中有一個embedRelation是依賴於「選項」:
// measureForm.class.php
if ($this->getOption('option') == "page_1") {
$this->embedRelation('Page');
}
,這就是我喜歡在我pageForm.class做。 php文件:
// pageForm.class.php
if ($this->getOption('option') == "page_1") { // Or != "page_2", or whatever
$this->embedRelation('Question');
}
我似乎無法找到一種方法來做到這一點。有任何想法嗎?
有沒有首選的Symfony做這種類型的操作的方式,也許沒有embedRelation?
感謝, -Trevor
按照要求,這裏是我的schema.yml:
# schema.yml
Measure:
connection: doctrine
tableName: measure
columns:
_kp_mid:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
description:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
frequency:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Page:
local: _kp_mid
foreign: _kf_mid
type: many
Page:
connection: doctrine
tableName: page
columns:
_kp_pid:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
_kf_mid:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
next:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
number:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
previous:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Measure:
local: _kf_mid
foreign: _kp_mid
type: one
Question:
local: _kp_pid
foreign: _kf_pid
type: many
Question:
connection: doctrine
tableName: question
columns:
_kp_qid:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
_kf_pid:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
text:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
type:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Page:
local: _kf_pid
foreign: _kp_pid
type: one
任何機會,你可以把一個示例架構在你的問題,因爲我有點不清楚你想達到什麼。 – johnwards 2010-05-27 07:14:08
當然,沒問題。我還更新了很多其他信息,以便更清楚。 – wulftone 2010-05-27 17:48:36