0

我正在使用带有 Doctrine 的 Symfony 1.2。我有一个带有两种语言翻译的 Place 模型。这个 Place 模型也有一个嵌套的集合行为。

我现在在创建属于另一个节点的新位置时遇到问题。我尝试了两种选择,但都失败了:

1 个选项

    $this->mergeForm(new PlaceTranslationForm($this->object->Translation[$lang->getCurrentCulture()])); 

如果我合并表单,会发生什么 place_id 字段的值是一个数组。我想是因为它正在等待一个带有 id 的真实对象。如果我尝试设置 place_id='' 则会出现另一个错误。

2个选项

$this->mergeI18n(array($lang->getCurrentCulture()));

public function mergeI18n($cultures, $decorator = null)
{
if (!$this->isI18n())
{
      throw new sfException(sprintf('The model "%s" is not internationalized.', $this->getModelName()));
}

$class = $this->getI18nFormClass();
foreach ($cultures as $culture)
{
      $i18nObject = $this->object->Translation[$culture];
      $i18n = new $class($i18nObject);
      unset($i18n['id']);
      $i18n->widgetSchema['lang'] = new sfWidgetFormInputHidden(); 

      $this->mergeForm($i18n); // pass $culture too
}
}

现在错误是:

Couldn't hydrate. Found non-unique key mapping named 'lang'.

看sql,id没有定义;所以它不能是重复的记录(我有一个唯一的键(id,lang))

知道会发生什么吗?

谢谢!

4

1 回答 1

0

看起来您遇到的问题与相互嵌入表单有关,这可能很棘手。您可能需要在父表单的 updateObject/bind 方法中执行操作,以使其正确地将其值传递给其子表单。

这篇文章值得一读:

http://www.blogs.uni-osnabrueck.de/rotapken/2009/03/13/symfony-merge-embedded-form/comment-page-1/

它提供了一些关于嵌入(和合并)表单如何工作的好信息。文章使用的技术可能对你有用,但我之前没有在 sf 中使用过 I18n,所以很可能有一个更优雅的内置解决方案?

于 2009-11-08T15:17:23.523 回答