我正在为我正在处理的项目创建一些小部件,似乎小部件无法从小部件外部访问任何其他类。我尝试为图像和 SiteTree 类添加一个 has_one 静态(参见下面的图像示例),当我尝试添加 cms 字段时遇到相同的错误:致命错误:调用成员函数 FormAction()第 139 行 /..../sapphire/forms/FormField.php 中的非对象
<?php
class AdBoxWidget extends Widget{
static $title = "";
static $cmsTitle = "Ad Box Widget";
static $description = "Ad Box widget. To add an image, Title and Link";
static $db = array(
"Title" => "Text",
"Link" => "Text",
"AdLinkText" => "Text"
);
static $defaults = array(
"Title" => 'Ad Title',
"Link" => 'http://',
"AdLinkText" => 'Click here for more info',
);
static $has_one = array(
'AdImage' => 'Image'
);
function getCMSFields(){
return new FieldList(
new TextField("Title", "Ad Title"),
new TextField("Link", "Ad Link"),
new TextField("AdLinkText", "Text for Link"),
new UploadField("AdImage", "Ad image")
);
}
function getAd(){
$output = new ArrayList();
$output->push(
new ArrayData(
array(
"Title" => $this->Title,
"Link" => $this->Link,
"AdLinkText" => $this->AdLinkText
)
)
);
return $output;
}
}