Jump to:

23552 Posts in 19349 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » url_handlers in 3.0

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

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

Page: 1
Go to End
Author Topic: 393 Views
  • biurex
    Avatar
    Community Member
    3 Posts

    url_handlers in 3.0 Link to this post

    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?

  • biurex
    Avatar
    Community Member
    3 Posts

    Re: url_handlers in 3.0 Link to this post

    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

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: url_handlers in 3.0 Link to this post

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

    393 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.