Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Director::redirectBack()

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: 2200 Views
  • julian
    Community Member
    17 Posts

    Director::redirectBack() Link to this post

    Hi all ok I'm playing around with my first form. My question is --

    in the example below, headers_sent(...) resolves to true so it does this almighty heavy weight 'redirecting to...'. How do I avoid this so that Director::redirect() calls header(...) instead.

    I looked at PageComments and it does the same thing as below but doesn't do the heavyweight redirect; what have I done wrong that means that a simple form submission (could it get any simpler? A single action) sends header information.

    thanks in advance!

    code below

       /** an opinion is a gesture of thought by user -- marking as favourite or comment or whatever. */
       function OpinionForm() {
          $loggedInMember = Member::currentUser();
          // user is authenticated, so return elements in the form.
          // if the user isn't authenticated, we will require them to when they do something.
          if( $loggedInMember ) {
             $artwork = $this->data();
             // we have a member so find whether this artwork was marked as favourite and highlight as appropriate.
             // returns a ComponentSet.
             $members = $artwork->getManyManyComponents('MemberFavourites');
             if( $members ) {
                $memberMap = $members->map();
                // this is not marked as a favourite, so give them the option to do this
                if( !$memberMap[$loggedInMember->ID]) {
                   $faveAction = new ImageFormAction('doMarkAsFavourite', 'Mark Artwork as favourite', 'mysite/images/fave_unselected.gif', 'mysite/images/fave_selected.gif' );         
                // ALREADY MARKED. Present option to unmark.
                } else {
                   $faveAction = new ImageFormAction('doUnmarkFavourite', 'Remove from favourites list', 'mysite/images/fave_selected.gif', 'mysite/images/fave_unselected.gif' );                        
             $fields = new FieldSet();
             $actions = new FieldSet( $faveAction );
             return new Form( $this, 'OpinionForm', $fields, $actions );
             // TODO -- change icon based on state of favourite
       /** user chose this to be a favourite against currently authenticated member. */
       function doMarkAsFavourite() {
          $loggedInMember = Member::currentUser();
          if( $loggedInMember ) {
             $artwork = $this->data();
             $members = $artwork->getManyManyComponents('MemberFavourites');
             $members->add( $loggedInMember );

  • Sam
    679 Posts

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

    Headers will have been sent because you've already outputted some text to the browser. Look for trailing newlines after the ?> tag in one of your PHP files, or a debug "echo" message.

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.