Symfony 1.4:Doctrine i18n 生成器问题

发布于 2024-09-15 11:01:12 字数 2742 浏览 1 评论 0原文

我的 i18n 学说模式和管理生成器有一个奇怪的问题。

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

架构如下所示:

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() 始终返回一个空字符串(数据库已正确填充了合适的数据)。

那么模式定义有什么问题吗?

第二个问题出现在 admin-generator 中:

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

生成器.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 名称。但在编辑视图中我总是收到错误“小部件'名称'不存在”

你们知道为什么会发生这种情况吗?我将非常感谢你的帮助。

编辑:

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

首先是示例的数据集:

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

有人有任何想法吗?我真的很绝望:(

I have a weird problem with my i18n doctrine schema and i.a. the admin generator.

(Please look at the edit part below first)

The schema looks like:

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 }

The first problem I have with sfForms:

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

This generates a radio butten set with the correct IDs, but empty name values.
Even when I try to get the name value by directly selecting a CargoSize object by ID and LANG, getName() always returns an empty string (the DB is filled correctly with suitable data).

So is somethng worng with the schema definition??

The second problem appears with the admin-generator:

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

The generator.yml looks like:

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:     ~

The funny thing is, that the list view shows me the i18n name. But in edit view I always get the error "widget 'name' does not exist".

Do you guys have any idea why this happens? I would be very thankful for your help.

EDIT:

I think the problem sits deeper, because this simple peace of code does note work:

First the datasets for the examples:

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

Does somebody has any idea? I'm really deperated :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在风中等你 2024-09-22 11:01:12

第一个问题:

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

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

第二个问题:

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

$this->embedI18n($cultures);

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

First problem :

The "names values" displayed are taken from the __toString() method result.
You could add the "method" options, like this :

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

Second problem :

Your form must embed the i18n form. To do this, put this in the configure method :

$this->embedI18n($cultures);

where $cultures is an array of your cultures codes.

决绝 2024-09-22 11:01:12

我发现了这个错误。由于某种原因,区域性被设置为“de_DE”,而不仅仅是“de”。
通过此设置,国际化行为的东西不起作用!

I found the bug. For some reason the culture was set to "de_DE" instead of just "de".
With this setting the i18n behavior stuff didn't work!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文