_preSave() and _postSave() explained?

Radi

Member
Could someone please, help me understand those two methods?
PHP:
    /**
    * Post-save handling.
    */
    protected function _postSave()
PHP:
    /**
    * Pre-save handling.
    */
    protected function _preSave()
Those are not very clear to me.

In my project, I am extending XenForo_DataWriter_User and my understanding is that I need to use those two methods to save the user data to the database.

Is there example code that I missed?
 
_preSave is called before saving. You should set any new fields in that method, before calling parent.

_postSave is called after saving. Perform any post save actions etc.

Liam
 
_preSave runs before the data is actually saved, and _postSave is run after the data is saved. _preSave could be used to validate things, _postSave could be used to alter something in another table if necessary after the data has been saved (such as updating the last post date on a thread when a new post is made)
 
Just remember that postsave is called before the transaction is committed (if my memory serves me right).

Liam
 
I am still not understanding how I am supposed to same my data

I created a new page: /index.php?account/email-preferences with a checkbox that I would like to save the state of in the DB.
PHP:
class SilverpopIntegration_XenForo_DataWriter_User extends XFCP_SilverpopIntegration_XenForo_DataWriter_User {}

HTML:
<form method="post" class="xenForm formOverlay NoFixedOverlay AutoValidator"
    action="{xen:link 'account/email-preferences-save'}"
    data-fieldValidatorUrl="{xen:link 'account/validate-field.json'}"
    data-redirect="yes">

I must be missing something...
 
There is then: _postSaveAfterTransaction() which occurs after the transaction finishes. You should use this for stuff like Alerts and other notifications.
 
Top Bottom