管理者ジェネレーター:state_idではなく、記事の状態を表示できないのはなぜですか?

StackOverflow https://stackoverflow.com/questions/3912534

  •  29-09-2019
  •  | 
  •  

質問

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.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:     ~
役に立ちましたか?

解決

わかった。

generator.ymlで、 display Line、Symfony(Doctrineを介して)は、表示する各フィールドに対応するモデルクラスでフィールド名を探します。フィールド名が存在しない場合、それは対応するものを探します getFieldName() 方法とそれを呼び出します。

あなたの例では、あなたは持っています Type 電話をかけるフィールド名として getType() - これにより関係が取得されます。デフォルトでは、Doctrineは、モデルを文字列に変換する場合(リストに表示する場合)、プライマリキー(場合はID値)を使用することを前提としています。

これを克服するには、aを追加します __toString() 次のように、あなたの教義に lib/model/doctrine/EcType.class.php ファイル:

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

また、管理されたリストに「タイプ」フィールドが表示されているのが表示されます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top