【问题标题】:Symfony 1.4: Updating form after embedding an i18n forms doesn't workSymfony 1.4:嵌入 i18n 表单后更新表单不起作用
【发布时间】:2012-05-23 05:20:48
【问题描述】:

我对管理中教义对象形式的内部化有疑问。表单工作得非常好,但后来我添加了对多种语言的支持。

架构如下所示:

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 表单中的字段(标题、内容),而主表单中的字段保持不变(父级、链接、类型)。

如果我从表单中删除嵌入,它会正确保存父级、链接和类型。如果我重新添加嵌入,它只会保存标题和内容。

你有没有遇到过类似的问题?我正在使用 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() 返回一个空字符串。

【问题讨论】:

  • 您使用什么版本的 symfony 1.4?在其他模块中您使用 embed i18n form 的情况如何?您能把您的 schema、generator.yml 和 form config 设置好吗?
  • @denys281 是的,当然。我添加了更多细节。我希望它有所帮助。
  • 我不记得为什么了,但我通常使用this tutorial in 来处理 i18n 字段。

标签: forms symfony1 internationalization symfony-1.4


【解决方案1】:

两天后我终于搞定了!奇怪的行为是由列“内容”引起的,尤其是它的名称与表的名称相同。如果我不使用 i18n 行为就没有问题。但是在添加 i18n 之后,一切都开始出现意外,但没有错误消息,所以我花了很长时间才弄明白。

所以列名不能与表名相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多