reference to deleteted record in actions/delete

A place for users and developers of the Xataface to discuss and receive support.

reference to deleteted record in actions/delete

Postby kurisusan » Tue Feb 05, 2008 4:42 am

Hi,

after the removal of a record I would like to initiate a redirect depending on the deleted record. How do I get a reference to the deleted record in actions/delete.php?

Cheers, Christian
kurisusan
 
Posts: 25
Joined: Sat Oct 27, 2007 2:40 am

Postby shannah » Thu Feb 07, 2008 12:37 am

Hi Christian,

Sorry for the delay in reply. In the current release you need to take this in 2 steps.

1. Use the afterDelete() trigger to store the deleted record in a global variable.

2. Use the action_after_delete() trigger, to perform your redirect.

e.g.
Code: Select all
// Executed after a record is deleted.
function afterDelete(&$record){
    global $deletedRecord;
    $deletedRecord =& $record;
}


// Executed after the delete action has been completed successfully
function action_after_delete(){
    global $deletedRecord;

    if ( $deletedRecord and $deletedRecord->val('name') == 'Harry' ){
        header('Location: http://harryshomepage.com');
        exit;

    }
}




The reason we don't put this redirect in the afterDelete() trigger is that the afterDelete() trigger may be used within a function call to delete records... best not to do redirects here.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby kurisusan » Thu Feb 07, 2008 5:55 am

Hi Steve,
thank you for the reply. I'm having problems though. The action_after_delete function seems not be called and it isn't mentioned in the docs by the way, at least not here: http://framework.weblite.ca/documentati ... n_triggers

Cheers, Christian
kurisusan
 
Posts: 25
Joined: Sat Oct 27, 2007 2:40 am

Postby shannah » Thu Feb 07, 2008 9:43 am

Sorry.. forgot that that trigger wasn't introduced in the current release... dev version has it.

You can add this trigger by making the following change to the actions/delete.php file:

Find the section that says:
Code: Select all
if ( !$failed ){
    header('Location: '.$_SERVER['HOST_URI'].DATAFACE_SITE_HREF.'?-table='.$query['-table'].'&--msg='.$msg);
    exit;
}


change it to:
Code: Select all
if ( !$failed ){
    import('Dataface/Utilities.php');
    Dataface_Utilities::fireEvent('after_action_delete', array('record'=>&$record));
    header('Location: '.$_SERVER['HOST_URI'].DATAFACE_SITE_HREF.'?-table='.$query['-table'].'&--msg='.$msg);
    exit;
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby kurisusan » Fri Feb 08, 2008 5:31 am

Thanks Steve.
Playing around with the other action triggers I noticed that the code in action_after_xxx function is executed before the redirection in actions/new actions/new_related is initiated. Consequently, putting redirection commands in the delegate class's action_after_xxx is useless.
Looking at your code
Code: Select all
if ( !$failed ){
    import('Dataface/Utilities.php');
    Dataface_Utilities::fireEvent('after_action_delete', array('record'=>&$record));
    header('Location: '.$_SERVER['HOST_URI'].DATAFACE_SITE_HREF.'?-table='.$query['-table'].'&--msg='.$msg);
    exit;
}

it seems that it might be necessary to move the redirection code one line up.

Christian
kurisusan
 
Posts: 25
Joined: Sat Oct 27, 2007 2:40 am

Postby kurisusan » Fri Feb 08, 2008 5:44 am

That's silly of course.... but anyway, as all action scripts, e.g. new/new_related/delete have redirection code you can't do any redirection within the action trigger functions, wrong?

Christian
kurisusan
 
Posts: 25
Joined: Sat Oct 27, 2007 2:40 am

Postby kurisusan » Fri Feb 08, 2008 5:45 am

wrong again! Sorry for the noise.
kurisusan
 
Posts: 25
Joined: Sat Oct 27, 2007 2:40 am

Postby shannah » Fri Feb 08, 2008 9:33 am

the code in action_after_xxx function is executed before the redirection in actions/new actions/new_related is initiated. Consequently, putting redirection commands in the delegate class's action_after_xxx is useless.


On the contrary, this positioning allows you to redirect to whatever page you want *before* it gets to the default redirect. If you redirect, then the script never reaches the default redirect. If you don't redirect, it just passes to the default redirect.

This technique can be used to add quite complex flow control to your applications. Sometimes I'll pass GET parameters to the form for the purpose of telling my after_action_xxx method where to redirect on success.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 14 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved