我正在嘗試使用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