我試圖將搜索結果返回到比執行搜索操作的位置更新的控制器。問題是Results
永遠不可從CustomSearchResultPage.ss
訪問。我已經爲我所認爲的事情添加了內聯評論,我在這裏想到了什麼?Silverstripe定製控制器數據/變量
// Customise content with results
$response = $this->customise(array(
'Results' => $results ? $results->getResults() : '',
));
if ($results) {
$response = $response->customise($results);
}
// Use CustomSearchResultPage.ss template
$templates = array('CustomSearchResultPage', 'Page');
// Create a new CustomSearchResultPage page
$page = CustomSearchResultPage::get_one('CustomSearchResultPage');
// Build a controller using the CustomSearchResultPage
$controller = CustomSearchResultPage_Controller::create($page);
// Add the custom data to the newly minted controller
$result = $controller->customise($response);
// Return the controller and tell it how to render
return $result->renderWith($templates);
該網頁似乎呈現如預期只是變量始終是空的......
糾正我,如果我錯了,但通過上面的方法,搜索結果將總是返回在'''Page_Controller'''上,最終我在'''CustomSearchResultPage_Controller'上返回結果相反 –