Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » How to get the url parameter

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: 3911 Views
  • px
    Avatar
    Community Member
    10 Posts

    How to get the url parameter Link to this post

    Hi! This might seem a little dumb question but I would just like to know how to get the URL Parameter of a certain site.
    For example, I have this url:

    http://www.mysite.com/forum/thread-one

    What i want is to get the forum AND the thread-one parameter.

    Any ideas?

    Thanks!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: How to get the url parameter Link to this post

    Hi

    The first part of the URL (forum) is the URLSegment (you can get it using $this->URLSegment). The second part (thread-one) is the action. To access it use:

    $action = Director::urlParam('Action');

  • px
    Avatar
    Community Member
    10 Posts

    Re: How to get the url parameter Link to this post

    hi! I tried it and I dump it to see if it shows a value but unfortunately, I get a NULL value :'(

    var_dump(Director::urlParam('Action'));
    exit();

    result is NULL

  • banal
    Avatar
    Community Member
    901 Posts

    Re: How to get the url parameter Link to this post

    Where in your code is that dump statement?

  • px
    Avatar
    Community Member
    10 Posts

    Re: How to get the url parameter Link to this post

    In my widget controller. In this method:

    function UserReviewsCommentFormStepOne() {
       $URLParams = Director::urlParam('Action');
          //$Segment = $URLParams['Action'];
          //$a = new HTTPRequest();
          
          var_dump($URLParams);
          exit();
       Session::clear('StepOneData');
    $fields = new FieldSet(
    new TextareaField("Pros","What did you like about this room?"),
    new TextareaField("Cons","What did you not like in this room?"),
    new OptionsetField("RecommendRoom",'Do you recommend this room?',array(
    'Y'=>'Yes',
    'N'=>'No'
    ),'Y'
    )
    );
          
    $actions = new FieldSet(new FormAction('doUserReviewsCommentFormStepOne', 'next'));
    $validator=new RequiredFields('Pros','Cons');
    $form = new Form($this, 'doUserReviewsCommentFormStepOne', $fields, $actions);

    return $form;
    }

    Also, I added a rule in my_config file for the thing that you said occur.
    Something like this:

    Director::addRules( 100, array(
       'reviews/$Action' => 'UserReviewsWidget_Controller'
    ));

  • banal
    Avatar
    Community Member
    901 Posts

    Re: How to get the url parameter Link to this post

    Hmm I never heard of a Widget Controller. I always thought Widgets don't have a controller themselves.
    Accessing the Action is certainly possible in a Page-Controller, can't help you with widgets though. Sorry.
    Maybe somebody else can give some pointers?

  • px
    Avatar
    Community Member
    10 Posts

    Re: How to get the url parameter Link to this post

    no no...I'm wrong. it's page controller actually

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