October: getSaveValue() after saving model

Created on 16 Oct 2018  路  6Comments  路  Source: octobercms/october

How to make the formwidget save the data only after the model is saved?

Question

All 6 comments

How to make the rain fall only after the ground is wet?

How to call a function in formwidget after saving model data?

P/S Sorry, translate via google translate

@Cryden, start from reading documentation first: https://octobercms.com/docs/database/model#events

i can use in formWidget this code?

public function init()
{
    Event::listen('model.afterSave', function() {
        // My function code run after Save model
    });
}

@cryden you could, but it would be better to target the specific model being touched by the form. Try something like this:

public function init()
{
    $this->model->bindEvent('model.afterSave', function () use ($model) {
        // your custom code here
    });
}

Thanks!

Was this page helpful?
0 / 5 - 0 ratings