Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Director::redirect()

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: 3174 Views
  • ccburns
    Avatar
    Community Member
    74 Posts

    Director::redirect() Link to this post

    Hi Guys,

    I have a form that submits and updates a data object but prior to the actual update I want to check whether a link actually exists on a page. If the link exists then the update can progress otherwise if the link doesn't exist then it should redirect the user back to the original form and give them a notice.

    But what is happening is that I am getting a warning

    [User Warning] Already directed to /placements/complete/3; now trying to direct to /placements

    So the code is failing the initial "if($this->checkforlink() == false){" check and doing the redirect, but then continuing on the execution of the rest of the updatecompletion() which is not what I want. I want to check for the link, if it fails, end execution and then redirect to the new page.

    If I try to exit() after Director::redirect('/placements/complete/'.$data['AdvertisementID']); then all I get is a white screen.

    I might be missing something extremely obvious here, but would love any help you might have.

    public function checkforlink() {

    // test to simulate a failed check for the link
    return false;

    }

    public function updatecompletion($data, $form) {

    if($this->checkforlink() == false){

    Session::set('notice', true);
    Session::set('noticeType', 'bad');
    Session::set('noticeText', 'Opps - It doesn\'t look like that link is actually showing up in the location you have provided yet. Please check that it exists before setting the placement as completed.');

    Director::redirect('/placements/complete/'.$data['AdvertisementID']);

    }

    // UPDATE Code goes in here
    if($Advertisement->write()){

    Session::set('notice', true);
    Session::set('noticeType', 'good');
    Session::set('noticeText', 'Okay, thanks for letting us know that this placement is completed.');

    Director::redirect('/placements');

    }else{

    Session::set('notice', true);
    Session::set('noticeType', 'bad');
    Session::set('noticeText', 'Opps - It doesn\'t look like that placement was for you. Nice try though ;)');

    Director::redirect('/placements');

    }
    }

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Director::redirect() Link to this post

    on your Director::redirect() try return Director::redirect()

  • ccburns
    Avatar
    Community Member
    74 Posts

    Re: Director::redirect() Link to this post

    SOLVED! Thanks

    Also I guess it should be

    return $this->redirect()

    As Director::redirect() is deprecated

    Thanks

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