Is row actually created before PHP Event ->on('postCreate'... ) is fired?
Is row actually created before PHP Event ->on('postCreate'... ) is fired?
I've noticed when using ...on('postCreate'...) in editor that the row doesn't actually seem to be created prior to this functions calling. In this 'postCreate' event, I try to use the $id parameter to get the id of the newly created row so I can generate a PDF from it... However, the row doesn't seem to exist when I call it.
It's odd, though, because it does return an appropriate $id integer, it's just that the row isn't actually created.
Rows are generated correctly if I don't call that PDF function.
This question has an accepted answers - jump to answer
Answers
Also, what's interesting, is the $id increments correctly if i put a die($id); statement in the code, but still no records are inserted into the DB. so, for example:
$id will increase by 1 each time, but no rows are actually inserted into the DB (presumably because of the die() )
Hi,
It is created, but it is created in a transaction which might explain why you are seeing the effect you are. Only when all rows have been edited (to allow for multi-row editing) is the transaction committed. This is to allow a rollback should something go wrong!
There are a couple of options I can think of to workaround this:
Editor->transaction()
method$editor->db()
to get the database instance Editor is using (which is in the transaction) and use that for your DB queries.1) is probably preferable in this case if you already have your code doing the database interaction required.
Allan
Thanks, Allan!
I ended up just sending the email after the Editor->process().... event. Thanks for giving me that detailed synopsis. I figured it was a transaction issue, and it's great to know that failsafe exists!