views:

14

answers:

1

I'm doing a blog engine in Symfony. Here's part of my schema :

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
(...)

In the administration pages, I want to display the type of the articles, but symfony only shows the type_id, why is that ?

EDIT: here's my generator.yml : I haven't modified it much yet.

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:     ~
+2  A: 

OK.

In your generator.yml, on the display line, Symfony (via Doctrine) will look for a field name in your model class that corresponds to each field you want to display. If the field name doesn't exist, it will then look for a corresponding getFieldName() method and call that.

In your example, you have Type as a field name, which will be calling getType() - this will fetch the relation in. By default, Doctrine assumes that when you want to convert a model to a string (eg for display in your list), you want to use the primary key - in your case, the ID value.

To overcome this, add a __toString() method as follows, to your Doctrine lib/model/doctrine/EcType.class.php file:

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

and you should see the 'type' field being displayed in your admin generated list.

richsage
So simple, it works right away. Thanks !
Manu