Silverstripe自定义控制器数据/变量

I'm trying to return search results to a new controller than where the search action was performed from. Problem is Results is never accessible from CustomSearchResultPage.ss. I've added inline comments for what I think is happening, am I right in my thinking here?

    // 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);

The page seems to render as expected just the variable is always empty...

Your explanation is a little hard to follow I'm afraid. So I'm answering for what I can ascertain as below:

  1. Performing a search. This requires loading a controller to do as such.
  2. Customising the current controller with the results
  3. RE-customising the current controller with itself.
  4. Setting the template for the current (double customised) controller.
  5. Disregarding all of the above.
  6. Fetching a random page (or an empty record).
  7. Creating a controller for the empty page.
  8. Customising the new controller with the customised controller of the current controller customised with itself.
  9. Returning that page, which shows no results.

You need only stop at step 4 (skip step 3), and return the customisation ($response).

If there is some reason you think you need another controller however (which seems superflous, but who knows), creating and then customising that one (only) before returning it would be better.

Being that you have only used this second controller for rendering a result, the URL will not have changed or anything. The whole thing seems beyond requirements.

A much more simple way to render a result from this action would probably be:

return $this ->customise(['Results' => $results ? $results->getResults() : null]) ->renderWith(['CustomSearchResultPage', 'Page']);

(from the top of my head, may need a little refining).