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()- これはリレーションを取得します。主キーを使用するには-あなたの場合はID値です。

これを克服するには__toString()、Doctrinelib/model/doctrine/EcType.class.phpファイルに次のようにメソッドを追加します。

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

管理者が生成したリストに「タイプ」フィールドが表示されているはずです。

于 2010-10-12T08:20:50.333 に答える