【问题标题】:Symfony 1.4: Doctrine i18n generator issuesSymfony 1.4:Doctrine i18n 生成器问题
【发布时间】:2011-04-02 17:29:59
【问题描述】:

我的 i18n 学说架构和 i.a. 有一个奇怪的问题。管理员生成器。

(请先看下面的编辑部分)

架构如下:

CargoSize:
  connection: doctrine
  actAs:
    Timestampable:      ~
    I18n:
      fields:                   [name, linkname, seoname, description]
  tableName: com_cargo_size
  columns:
    id:                                     { type: integer(11), notnull: true, unsigned: true, primary: true, autoincrement: true }
    name:                                   { type: string(50),  notnull: true }
    linkname:                               { type: string(100), notnull: true }
    seoname:                                { type: string(100), notnull: true }
    description:                            { type: string(255), notnull: true }

sfForms 遇到的第一个问题:

new sfWidgetFormDoctrineChoice(array('model' => 'CargoSize', 'expanded' => true, 'multiple' => false), array('style' => 'list-style-type: none; display: inline;'))

这会生成一个带有正确 ID 但名称值为空的单选按钮集。 即使我尝试通过 ID 和 LANG 直接选择 CargoSize 对象来获取名称值,getName() 总是返回一个空字符串(数据库中正确填充了合适的数据)。

那么架构定义有什么问题吗??

第二个问题出现在管理员生成器上:

php symfony doc:generate-admin --module=cargo_size admin CargoSize

generator.yml 看起来像:

generator:
  class: sfDoctrineGenerator
  param:
    model_class:           CargoSize
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          cargo_size
    with_doctrine_route:   true
    actions_base_class:    sfActions

    config:
      actions: ~
      fields:  ~
      list:
        display: [name, lang]
      filter:  ~
      form:    ~
      edit:
        display: [name]
      new:     ~

有趣的是,列表视图显示了 i18n 名称。但在编辑视图中,我总是收到错误 “widget 'name' 不存在”

你们知道为什么会这样吗?非常感谢您的帮助。

编辑:

我认为问题更深层次,因为这种简单的代码和平确实有效:

首先是示例的数据集:

cargo_size
id  created_at              updated_at
1   2010-04-22 21:37:44     2010-04-22 21:37:44

cargo_size_translation
id      name    linkname    seoname     description     lang
1       klein   klein       klein       klein           de
1       small   small       small       small           en

$c = Doctrine::getTable('CargoSize')->findOneBy('id', 1); 
echo $c;  // (toString exists)

// Output: Catchable fatal error: Method CargoSize::__toString() 
// must return a string value in 
// /var/www/.../apps/frontend/modules/start/templates/indexSuccess.php on line 1

echo $c->getName();
// Output: nothing

有人知道吗?我真的很沮丧:(

【问题讨论】:

    标签: internationalization symfony1 doctrine symfony-1.4 admin-generator


    【解决方案1】:

    第一个问题:

    显示的“名称值”取自 __toString() 方法的结果。 您可以添加“方法”选项,如下所示:

    new sfWidgetFormDoctrineChoice(array('model' => 'CargoSize', 'expanded' => true, 'multiple' => false, 'method' => 'getName'), array('style' => 'list-style-type: none; display: inline;'))
    

    第二个问题:

    您的表单必须嵌入 i18n 表单。为此,请将其放在 configure 方法中:

    $this->embedI18n($cultures);
    

    其中 $cultures 是您的文化代码数组。

    【讨论】:

    • 这很有趣,我已经有了 toString。但是现在添加了 embedI18n 之后,似乎所有问题都解决了,不仅在 sfForm 中,而且在表单独立位置 O_o 中。所以非常感谢这个提示:)
    • 遗憾的是问题仍然存在,我不知道为什么,但是当我想通过以下方式获取名称属性时: $cargo_size->getName(); //(每个语言的值都在数据库中)它返回一个空字符串。你有更多的想法可能是什么问题吗?
    【解决方案2】:

    我发现了错误。出于某种原因,文化被设置为“de_DE”,而不仅仅是“de”。 使用此设置,i18n 行为的东西不起作用!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-21
      • 2011-05-26
      • 2011-08-19
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2020-03-28
      • 1970-01-01
      相关资源
      最近更新 更多