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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

url_handlers in 3.0


Go to End


3 Posts   1131 Views

Avatar
biurex

Community Member, 3 Posts

22 January 2013 at 12:53am

Hi.
I've been googling this for the last half an hour, and no success.
I cannot find any good tutorial about url_handlers.
What I need to make working is:

1. I have a MyPage class and an instance with a following URLSegment: 'http://mydomain.com/mypage'
2. Now I need to support ANY action in this page class: 'http://mydomain.com/mypage/lorem' should open 'http://mydomain.com/mypage' with Action param: 'lorem'.

I declared this in MyPage_Controller:

public static $url_handlers = array(
'' => 'index',
'$Action' => 'index',
);

public function index() {
print_r($this->getRequest()->params());
return array();
}

but calling http://mydomain.com/mypage/lorem gives me the following error:

[Warning] substr() expects parameter 1 to be string, array given
GET /mypage/lorem
Line 79 in /var/www/vhosts/pitax.internetex.pl/htdocs/framework/control/ContentNegotiator.php

However it prints the params correctly:
Array ( [URLSegment] => mypage [Action] => lorem [ID] => [OtherID] => [Controller] => ModelAsController )
so that 'lorem' is considered as an Action.

anyone know what's wrong here?

Avatar
biurex

Community Member, 3 Posts

22 January 2013 at 1:04am

Edited: 22/01/2013 1:04am

and the stack trace:

Trace

substr(Array,0,5)
ContentNegotiator.php:79
ContentNegotiator::enabled_for(SS_HTTPResponse)
ContentNegotiator.php:83
ContentNegotiator::process(SS_HTTPResponse)
Controller.php:174
Controller->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:197
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ModelAsController.php:68
ModelAsController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:307
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:119
Director::direct(/mypage/lorem,DataModel)
main.php:126

Avatar
copernican

Community Member, 189 Posts

24 January 2013 at 5:42am

what is the purpose of "return array()" in the index function? Removing that fixes the error for me.