【发布时间】:2013-02-27 03:28:30
【问题描述】:
我正在尝试编写一个函数来显示来自 Holder Page 上子页面的图像。
因为 SilverStripe 在模板上缺少一些功能,所以我认为最好在控制器中处理它们。
我需要一些只能在 php 中完成的条件语句。
控制器.php
public function LatestWork() {
$works = WorkPage::get();
$i = 1;
$html = "";
foreach ($works as $work) {
//Build the IMage Object so we can add it to the Work Object
$ImageObj = File::get()->byID($work->FeaturedImageID);
if ($this->is_odd($i)) {
$html .= "<div class='row'>";
$span = "span8";
} else {
$span = "span4";
}
$html .= "<div class = '$span'>" . $ImageObj->croppedImage(200,100) . "</div>";
if ($this->is_even($i) || $i == $works->Count()) {
$html .= "</div>";
}
$i++;
}
return $html;
}
当它在视图中处理时,div 和 span 存在,但图像不存在。代码中有更多条件,但这只是基本版本。 它改为显示“Image_Cached”。
如何让它显示图像?
【问题讨论】:
-
当您返回 $ImageObj->croppedImage(200,100) 时没有 html 或其他任何内容,例如:返回 $ImageObj->croppedImage(200,100) 。 " " 它会显示图像,但只要您添加任何内容,它就会显示 Image_cache
标签: silverstripe