Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Director::redirect()


Go to End


3 Posts   10546 Views

Avatar
ccburns

Community Member, 79 Posts

6 January 2012 at 12:13am

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');
                
            }
}

Avatar
copernican

Community Member, 189 Posts

6 January 2012 at 2:41am

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

Avatar
ccburns

Community Member, 79 Posts

6 January 2012 at 3:36am

SOLVED! Thanks

Also I guess it should be

return $this->redirect()

As Director::redirect() is deprecated

Thanks