Silverstripe 3.0.5에서 ShortCode 함수에서 many_many 관계의 이미지를 쿼리하려고합니다. SQLQuery()를 사용하여 쿼리 할 때 (Debug) 모든 데이터를 볼 수 있지만 SetWidth 또는 CroppedImage와 같은 Image/GD 함수를 어떻게 사용하는지 알지 못합니다. 일반적으로 SQLQuery에 대해 쿼리하지 않을 때 템플릿의 이미지와 함께 사용할 수 있습니다. . 템플릿에서 $ Filename을 직접 참조 할 수 있습니다. 그러나 템플릿에서 이미지 조작 함수 (SetWidth, CroppedImgae ...)를 사용하여 데이터를 쿼리하는 방법 또는 GalleryShortCodeHandler에서 GalleryImages를 어떻게 얻을 수 있습니까?Silverstripe : ShortCodeHandler에서 many_many를 쿼리하고 이미지 조작 함수를 사용하십시오.
class Page extends SiteTree {
$many_many = array(
"GalleryImages"=>"GalleryImage"
);
...
public function GalleryShortCodeHandler($arguments,$caption = null,$parser = null) {
$sqlQuery = new SQLQuery();
$sqlQuery->from("GalleryImage");
$sqlQuery->addLeftJoin('Page_GalleryImages','"GalleryImage"."ID" = "Page_GalleryImages"."GalleryImageID"');
$sqlQuery->addLeftJoin('File','"File"."ID" = "Page_GalleryImages"."GalleryImageID"');
$sqlQuery->addWhere('"PageID" = ' . Controller::curr()->ID);
$rawSQL = $sqlQuery->sql();
$result = $sqlQuery->execute();
$returnedRecords = new ArrayList();
foreach($result as $row) {
$returnedRecords->push(new ArrayData($row));
}
$customise = array();
$customise["Images"] = $returnedRecords;
// Debug::show($customise);
$template = new SSViewer("Gallery");
return $template->process(new ArrayData($customise));
}
...
class GalleryImage extends Image {
static $db = array(
"Descrition" => "Text"
);
static $belongs_many_many = array(
"Pages" => "Page"
);
...
Debug output looks like:
Debug (Page::GalleryShortCodeHandler() in Page.php:211)
Images =
ArrayList
ID = 65
Descrition =
PageID = 17
GalleryImageID = 65
SortOrder = 1
ClassName = GalleryImage
Created = 2013-04-24 14:20:28
LastEdited = 2013-04-24 14:20:28
Name = xyz.png
Title = xyz
Filename = assets/Gallery/xyz.png
Content =
ShowInSearch = 1
ParentID = 1
OwnerID = 2
...
@jfbarrois! 이것은 내가 한 것입니다. ORM 측에서 Image가 파일 - 세부 정보를 자동으로 가져 오기 때문에 File to Join은 더 이상 필요하지 않습니다. – munomono