我正在尝试使用YouTube小部件,但它似乎在Silverstripe 3中存在问题,并且未将DataObjectSet传递给模板,因此结果,我无法将我的数据传递给模板。所有的值都在CMS中正确显示,只有在模板中它们没有通过,所以它似乎是SS3中DataObjectSet的问题。我已经非常广泛地进行了搜索,但在SS3中找不到任何提及它的提示。Silverstripe 3 - 为什么数据没有传递给模板
class YoutubeWidget extends Widget{
static $title = "My favorite video";
static $cmsTitle = "Your tube widget";
static $description = "This widget can embed clips from youtube.com";
static $db = array(
"Width" => "Int",
"Height" => "Int",
"URL" => "Text",
"Title" => "Text"
);
static $defaults = array(
"Width" => 283,
"Height" => 182
);
function getCMSFields(){
return new FieldList(
new NumericField("Width", "Video Width"),
new NumericField("Height", "Video Height"),
new TextField("URL", "Video URL"),
new TextField("Title","Title or a note about this video")
);
}
function GetVideoData(){
$output = new DataObjectSet();
$output->push(
new ArrayData(
array(
"Width" => $this->Width,
"Height" => $this->Height,
"URL" => $this->URL,
"Title" => $this->Title
)
)
);
return $output;
}
}
没有任何变量正在填充模板中。
<% control GetVideoData %>
<object width="$Width" height="$Height">
<param name="movie" value="$URL"></param>
<param name="allowFullScreen" value="true"></param>
<embed src="$URL" type="application/x-shockwave-flash" allowfullscreen="true" width="$Width" height="$Height"></embed>
</object>
<p style="text-align:center;">$Title</p>
<% end_control %>
如果我换在<%的控制,如果GetVideoData%>它不访问控制,指示正在返回什么都没有,也会发生这种情况,即使我改变GetVideoData函数只返回一个字符串。即return "asdf";
欢迎来到stackoverflow.com! – mafp