Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Pass Request to another Controller


Go to End


1241 Views

Avatar
juergr

Community Member, 17 Posts

5 September 2012 at 5:55am

Is it possible to pass the whole Request to another Controller from within a Controller action?

Lets say we have something like this:

The First Controller:

class Controller1 extends Page_Controller {
  public static $url_handlers = array(
    '$Action/$ID'  => 'doStuff'
  )

  function doStuff($request) {
    if($request->param['Action'] == 'special') {
       // Pass control to my SpecialController
    }
    return $this;
  }
}

The Special Controller

class SpecialController extends Page_Controller {
  public static $url_handlers = array('$ID' => 'display');

  public function display($request) {
     return $this;
  }
}

How can I do something like this? I've tried it with

return new SpecialController();
and
$controller = new SpecialController();
return $controller->handleRequest($request);

But all I get is:

[User Warning] popCurrent called on ModelAsController controller, but it wasn't at the top of the stack

Any solutions for this?