我在管理中对教条对象形式的内化有问题。表单工作得很好,但后来我添加了对多种语言的支持。
Schema看起来像这样:
content:
actAs:
Timestampable: ~
I18n:
fields: [title, content]
columns:
parent: { type: integer }
title: { type: string(255), notnull: true, unique: true }
slug: { type: string(255), notnull: true, unique: true }
content: { type: string }
link: { type: string(255) }
ord: { type: integer }
type: { type: integer, default: 0 }
relations:
content: { onDelete: CASCADE, local: parent, foreign: id }
indexes:
parent: { fields: [parent] }
slug: { fields: [slug] }
type: { fields: [type] }
管理员生成器:
generator:
class: sfDoctrineGenerator
param:
model_class: content
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: content
with_doctrine_route: true
actions_base_class: sfActions
config:
actions: ~
fields:
title: { is_real: false }
typeFull: { label: Type }
list:
display: [=title, typeFull]
sort: ord
max_per_page: 100
filter:
class: false
form:
class: adminContentForm
edit: ~
new: ~
最后一个表格:
class adminContentForm extends BasecontentForm
{
public function configure()
{
unset($this['slug'], $this['ord'], $this['created_at'], $this['updated_at']);
$this->embedI18n(array('de', 'fr'));
$this->widgetSchema->setLabel('de', 'Deutsch');
$this->widgetSchema->setLabel('fr', 'French');
}
}
我没有更改动作类。
当我想创建一个新条目时,一切正常。但是当我想要更新现有条目时会出现一个奇怪的问题:它只保存嵌入式i18n表单中的字段(标题,内容),而主表单中的字段保持不变(父级,链接,类型)。 / p>
如果我从表单中删除嵌入,它会正确保存parent,linky和type。如果我添加嵌入,它只保存标题和内容。
你遇到过类似的问题吗?我正在使用Symfony 1.4.17。编辑:
如果我将其添加到actions.class.php中的processForm()方法中调试:
var_dump($form->getValue('link'));
$content = $form->save();
var_dump($content->getLink());
exit();
...我发现字段链接中的值已正确发送,但保存表单后,该值不会保存。 $ form-> getValue('link')返回一个正确的值,但$ content-> getLink()返回一个空字符串。
答案 0 :(得分:2)
两天后我终于明白了!奇怪的行为是由列“内容”引起的,特别是它的名称与表的名称相同。如果我不使用i18n行为没有问题。但是在添加了i18n后,一切都开始出乎意料,但没有错误信息,所以我花了很长时间才搞清楚。
因此,列名不能与表名相同。