I have been reading the documentation and I am curious as to what are
the best practices for using setNextEvent and runEvent are. They
appear to be interchangeable and wasn't sure how the framework is
expecting them to be used.
setNextEvent is used to do a redirect at the end of a request, so you
current request will finish up and then do an http redirect (302 if I
recall) to the event you specify. runEvent executes another event in
the context of your current request, just invoking it but not
redirecting to it, so you have only 1 request total.
Example scenarios:
You have an edit form process that the form posts to. After you
validate the data and save it to the db, you would use setNextEvent to
redirect to, say, a listing page that shows the newly edited item
along with others in a list.
You are doing a bulk import of data from a file. You have one event
that knows how to import a single item, call it ImportItem and then
you have a higher level task called, perhaps, ImportAllItems.
ImportAllItems would know how to find the file, read it in and then
loop over it. For each iteration of the loop, you might call
RunEvent('foo.ImportItem') and pass it the data it needs for that one
item to import. After the loop is done, your request would finish
normally but you might have run the ImportItem event 10 times.
I have a log in form, the form processes to a dologin method, running
a series of events using runEvent to setup a user struct in the cb
storage container, at the end of all the steps I want to send the user
to a search page, basically the default logged in page - if I used
setNextEvent it was taking forever, so, I switched to runEvent which
worked speedy as expected.
If I interpret your feedback correctly using runEvent in this scenario
would be accurate because the entire chain of events is considered one
event so runEvent should be used correct? If the user password combos
fail for any reason, I am using setNextEvent to send them back to the
log in page.
Based on your example am I viewing this correctly?