2016-08-22 57 views
1

我有一個模特兒管理模特,我想在gridfield下面添加描述。通常這是通過設置->setDescription('Note in here')如何將描述添加到通過ModelAdmin管理的模型中?

當你通過ModelAdmin進行管理時,你如何做到這一點?

<?php 

class FormDropdownModelAdmin extends ModelAdmin { 

    private static $managed_models = array(
     'HearAboutUsItem' 
    ); 

    private static $url_segment = 'form-dropdown-items'; 

    private static $menu_title = 'Form Dropdown Items'; 

} 

回答

3

您可以重載ModelAdmin上的getEditForm方法,並將描述應用於該字段。

public function getEditForm($id = NULL, $fields = NULL) { 
    $form = parent::getEditForm($id, $fields); 

    $form->Fields()->fieldByName('HearAboutUsItem') 
     ->setDescription('This is my description'); 
    return $form; 
} 
+0

謝謝,這是有效的。然而,我現在已經添加了多個模型到這個Modeladmin,並且當我點擊標籤訪問另一個模型時,它會拋出:致命錯誤:調用一個非對象的成員函數setDescription() - 我想我可以只是複製你的代碼,並改變fieldByName('AnotherModel')中的模型 - 但是nope不起作用。有關如何向ModelAdmin中的每個託管模型添加描述的任何想法? – ifusion

+0

用'$ this-> modelClass'替換'AnotherModel' –

+0

這可以工作,但是會爲每個模型顯示相同的描述。如果你想爲每個模型獨特的描述你如何做到這一點? – ifusion