Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » urlParams from within DataObject

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

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

Page: 1
Go to End
Author Topic: 1584 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    urlParams from within DataObject Link to this post

    Hi guys,

    I used to have a function Current() on my Category-class (extends DataObject):

    function Current()
    {
        if($_GET['Title'] == $this->Title) return " class='current'";
    }

    Now I rewrote some stuff so I don't have to use $_GET anymore, but use urlParams instead.
    But the problem is, how do I call it from within my dataobject?

    function Current()
    {
        if(????->urlParams['ID'] == $this->Title) return " class='current'";
    }

    Any ideas?
    (That's not the main function that uses the urlparams, but the other functions are on the pagecontrollers..)

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: urlParams from within DataObject Link to this post

    Fixed, thanks to MattSS.

    Quite easy actually: when you're in a model instead of a controller you can access urlParams by

    Director::urlParams() -> this gives an array of all them
    or
    Director::urlParam('the one you want')

    1584 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.