2010-10-12 14 views
0

我正在做Symfony中的博客引擎。這裏是我的架構的一部分:管理生成器:爲什麼我無法顯示文章的狀態,而不是state_id?

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:  ~ 
+0

你可以從你的管理生成器模塊發佈你的generator.yml嗎? – richsage 2010-10-12 07:57:38

回答

3

好的。

在您的generator.yml中,在display行上,Symfony(通過Doctrine)將在模型類中查找與您要顯示的每個字段對應的字段名稱。如果字段名稱不存在,它將查找相應的方法並調用該方法。

在你的例子中,你有Type作爲字段名稱,它將調用getType() - 這將獲取關係。默認情況下,Doctrine假定當你想將模型轉換爲字符串時(例如用於顯示你的列表),你想使用主鍵 - 在你的情況下,ID值。

爲了克服這一點,添加一個__toString()方法如下,以你的學說lib/model/doctrine/EcType.class.php文件:

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

,你應該看到在您的管理員生成的列表所顯示的「類型」字段。

+0

這麼簡單,它馬上就可以工作。謝謝 ! – Manu 2010-10-12 08:23:18

相關問題