0

早上好,

我一直在尝试使用 removeByName 方法,但它不起作用。我基本上是想在由管理对象的 ModelAdmin 生成的表单中隐藏我的 DataObject 中的一个字段。

请参阅下面的示例代码:

///DataObject snippet...
class MyObject extends DataObject{
   public static $db = array(
       'Title' => 'Varchar',
       'Desc' => 'Text',
       'Template' => 'HTMLText',
   );

   //@Override
   public function getCMSField(){
       $fields = parent::getCMSField();
       $fields->removeByName('Template'); /// DOESN'T WORK!!!
       return $fields;
   }

}//class

注意:我没有收到任何错误。我仍然像往常一样在表单(添加和编辑)上看到该字段。

任何帮助表示赞赏,谢谢。

4

1 回答 1

0

Okay, I found the issue.

I was just going over the API again for the millionth time, and recognized that I've named the function wrong. See correction below:

///Correction, forgot to add the 's' at the end of both the function and the parent call.
public function getCMSFields(){
    $fields = parent::getCMSFields();
}

I can understand an error not being generated in Apache logs for the function because it's legit. But as for the parent call, it should of generated an error since the method don't exists. (Theory: Perhaps, since the function was never actually being called, the parent call wasn't being executed and thus no errors [run-time error]).

于 2014-12-01T15:00:20.407 回答