我在使用Symfony 1.2和Doctrine。我有一个用两种语言翻译的地方模型。这个地方模型也有一个嵌套的集合行为。
我现在在创建一个属于另一个节点的新位置时遇到了问题。我试过两种选择,但都失败了:
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))
知道会发生什么吗?
谢谢!
发布于 2009-11-08 15:17:23
看起来,您所遇到的问题与在彼此之间嵌入表单有关,这可能是很棘手的。您可能需要在父窗体的updateObject/bind方法中执行一些操作,以使其正确地将其值传递给其子窗体。
这篇文章值得一读:
http://www.blogs.uni-osnabrueck.de/rotapken/2009/03/13/symfony-merge-embedded-form/comment-page-1/
它提供了一些关于嵌入(和合并)形式如何工作的好信息。本文使用的技术可能适用于您,但我以前没有在sf中使用过I18n,所以很可能有一个更优雅的解决方案是内置的?
https://stackoverflow.com/questions/1696289
复制相似问题