Symfony:embedRelation() 控制嵌套多层关系的选项
我试图为嵌套的 embedRelation() 实例设置一些条件语句,但无法找到一种方法来获取第二个 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
I'm trying to set some conditional statements for nested embedRelation() instances, and can't find a way to get any kind of option through to the second embedRelation.
I've got a "Measure->Page->Question" table relationship, and I'd like to be able to choose whether or not to display the Question table. For example, say I have two "success" pages, page1Success.php and page2Success.php. On page1, I'd like to display "Measure->Page->Question", and on page2, I'd like to display "Measure->Page", but I need a way to pass an "option" to the PageForm.class.php file to make that kind of decision. My actions.class.php file has something like this:
// actions.class.php
$this->form = new measureForm($measure, array('option'=>$option));
to pass an option to the "Page", but passing that option through "Page" into "Question" doesn't work.
My measureForm.class.php file has an embedRelation in it that is dependent on the "option":
// measureForm.class.php
if ($this->getOption('option') == "page_1") {
$this->embedRelation('Page');
}
and this is what i'd like to do in my pageForm.class.php file:
// pageForm.class.php
if ($this->getOption('option') == "page_1") { // Or != "page_2", or whatever
$this->embedRelation('Question');
}
I can't seem to find a way to do this. Any ideas?
Is there a preferred Symfony way of doing this type of operation, perhaps without embedRelation?
Thanks,
-Trevor
As requested, here's my 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我决定改用 embedForm() 。它最终是一些 Doctrine_Query::create()->select()... 和 Doctrine::getTable 命令,后跟一些 foreach 循环和 embedForm 语句。 embedRelation 就这么多!
I've decided to use embedForm() instead. It ended up being some Doctrine_Query::create()->select()... and Doctrine::getTable commands followed by some foreach loops and embedForm statements. So much for embedRelation!