代码之家  ›  专栏  ›  技术社区  ›  ownking

symfony 1.4:条令i18n生成器问题

  •  1
  • ownking  · 技术社区  · 14 年前

    我的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但名称值为空的无线Butten集。 即使我试图通过id和lang直接选择cargosize对象来获取name值,get name()也总是返回一个空字符串(数据库中正确地填充了适当的数据)。

    那么,是不是有人在研究模式定义??

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

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

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

    编辑:

    我认为问题更深层,因为这种简单的代码和平确实起到了作用:

    首先是示例的数据集:

    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
    

    有人知道吗?我真的被开除了:(

    2 回复  |  直到 12 年前
        1
  •  2
  •   JF Simon    14 年前

    第一个问题:

    显示的“名称值”取自u 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是您的文化代码数组。

        2
  •  1
  •   ownking    14 年前

    我找到了虫子。出于某种原因,文化被设置为 德埃德 而不仅仅是“de”。 有了这个设置,i18n行为就不起作用了!