1

我正在尝试为嵌套的 embedRelation() 实例设置一些条件语句,但找不到通过第二个 embedRelation 获得任何类型的选项的方法。

我有一个“Measure->Page->Question”表关系,我希望能够选择是否显示 Question 表。例如,假设我有两个“成功”页面,page1Success.php 和 page2Success.php。在 page1 上,我想显示“Measure->Page->Question”,在 page2 上,我想显示“Measure->Page”,但我需要一种将“option”传递给 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?

谢谢,-特雷弗

根据要求,这是我的 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
4

1 回答 1

0

我决定改用 embedForm() 。它最终成为一些 Doctrine_Query::create()->select()... 和 Doctrine::getTable 命令,然后是一些 foreach 循环和 embedForm 语句。embedRelation 就这么多!

于 2010-06-08T17:30:29.410 回答