我正在使用Symfony进行博客引擎。这是我的模式的一部分:

alt text

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:
  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:     ~
有帮助吗?

解决方案

好的。

在您的发电机中,在 display 线,Symfony(通过学说)将在模型类中寻找与要显示的每个字段相对应的字段名称。如果字段名称不存在,它将寻找相应的 getFieldName() 方法并称之为。

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

为了克服这一点,添加一个 __toString() 方法如下,对您的学说 lib/model/doctrine/EcType.class.php 文件:

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

而且,您应该在管理生成列表中看到“类型”字段。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top