0

我在 Symfony 中做一个博客引擎。这是我的架构的一部分:

替代文字

Content:
  connection: doctrine
  tableName: ec_content
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
(...)
  relations:
    Author:
      local: author_id
      foreign: id
      type: one
    State:
      local: state_id
      foreign: id
      type: one
    Type:
      local: type_id
      foreign: id
      type: one
(...)

在管理页面,我想显示文章的类型,但是symfony只显示type_id,这是为什么呢?

编辑:这是我的 generator.yml :我还没有修改太多。

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

    config:
      actions: ~
      fields:  ~
      list:
        title: Brouillons
        display: [Type, State, title, link]
      filter:  ~
      form:    ~
      edit:    ~
      new:     ~
4

1 回答 1

3

好的。

在您的 generator.yml 中display,Symfony(通过 Doctrine)将在您的模型类中查找与您要显示的每个字段相对应的字段名称。如果字段名称不存在,它将寻找相应的getFieldName()方法并调用它。

在您的示例中,您有Type一个字段名称,它将被调用getType()- 这将获取关系。默认情况下,Doctrine 假设当您想要将模型转换为字符串(例如,在列表中显示)时,您想要使用主键 - 在您的情况下,是 ID 值。

为了克服这个问题,在你的 Doctrine文件中添加__toString()如下方法:lib/model/doctrine/EcType.class.php

class EcType extends BaseEcType
{
  public function __toString()
  {
    return $this->type;
  }
}

您应该会在管理员生成的列表中看到“类型”字段。

于 2010-10-12T08:20:50.333 回答