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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Director::addRules() bug?

Go to End

2 Posts   1776 Views


Forum Moderator, 4102 Posts

8 December 2008 at 11:43am

Edited: 08/12/2008 11:45am

I think I may have found a bug in the Director.php code. Correct me if I'm wrong.

If I use Director::addRules() to specify a custom controller for a URL like this:

Director::addRules(50, array ('myurl/$Action/$Class' => 'My_Controller'));

The getControllerForURL() function in the Director class will parse that array and get the name of the controller as a string ("$controller"), and it will instantiate the "My_Controller" object like this:

$controllerObj = new $controller();

However, every descendant of the Controller class expects a "$dataRecord" variable to be passed into it. Silverstripe errors out when I use anything but "Controller " as my custom controller because the __construct() method is missing argument 1.

Am I missing something? Seems crazy!


Forum Moderator, 4102 Posts

9 December 2008 at 6:21am

Hmm.. Never mind. It seems the only accepted custom controller you can use is a subclass of Controller.