17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2002 Views |
-
Director::redirectBack()

19 March 2007 at 2:16am Last edited: 19 March 2007 2:16am
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!
Jcode 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 );
Director::redirectBack();
}
} -
Re: Director::redirectBack()

19 March 2007 at 11:36am
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.
| 2002 Views | ||
|
Page:
1
|
Go to Top |


