Jump to:

17691 Posts in 4607 Topics by 2180 members

General Questions

SilverStripe Forums » General Questions » Could someone tell me what the purpose of the first few lines of Controller::redirect method are?

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

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba

Page: 1
Go to End
Author Topic: 1492 Views
  • ImacSS
    Avatar
    Community Member
    31 Posts

    Could someone tell me what the purpose of the first few lines of Controller::redirect method are? Link to this post

    Running into a problem where I am encountering the error message produced from the first few lines of the Controller::redirect() method - and wondering if someone could explain the rationale behind this logic?

    if($this->response->getHeader('Location')) {
    user_error("Already directed to " . $this->response->getHeader('Location') . "; now trying to direct to $url", E_USER_WARNING);
    return;
    }

    Just curious, as I'm finding it difficult to come up with a work around given these lines.

    Thanks

    UPDATE: Never mnd - this doesn't effect live deployment as it's only a warning, so commenting it from my local development machine...

  • Willr
    Avatar
    Forum Moderator
    4584 Posts

    Re: Could someone tell me what the purpose of the first few lines of Controller::redirect method are? Link to this post

    FYI Its to prevent having Director::redirect() commands redirecting the user multiple times.

  • anselm.dk
    Avatar
    Community Member
    14 Posts

    Re: Could someone tell me what the purpose of the first few lines of Controller::redirect method are? Link to this post

    So how would you approach only redirecting the user to the first appearing Director::redirect?

    I'm getting the 'Already redirected' warning, and have no clue of how to get around it (I'm building a 'maintenance offline' settings script):

             $bolMaintenanceRedirect = true;
             if (Member::currentUser()) {
                if(Member::currentUser()->isAdmin()) {
                $bolMaintenanceRedirect = false;
                }
             }
             if ($bolMaintenanceRedirect){
                if (Director::urlParam("Controller") != 'Security') {
                   if (Director::urlParam("Action") != 'login') {
                      Director::redirect('downformaintenance.html');            
                   }
                }
             }   

  • Willr
    Avatar
    Forum Moderator
    4584 Posts

    Re: Could someone tell me what the purpose of the first few lines of Controller::redirect method are? Link to this post

    Is it calling that function twice? If you put a Debug::message("test"); inside that last if does it show twice?. You could be redirecting as well as SilverStripe doing something with the security redirect

  • anselm.dk
    Avatar
    Community Member
    14 Posts

    Re: Could someone tell me what the purpose of the first few lines of Controller::redirect method are? Link to this post

    I was looking for a way to overrule any other redirects that would have been set before. I thought maybe there would be a method for that?
    I ended up by fixing this by setting some preferences, and a couple of if statements.

    Thanks for the fast reply!

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