beforeSave Trigger[Permalink]Back to Delegate class methods SynopsisThe beforeSave trigger can be implemented in any table's Delegate Class Methods? to perform functionality that should be run *before* a record of that table is saved. This is a useful place to insert additional field values depending on the input of the save record form. This method is called both when records are inserted and when existing records are updated. Some other triggers include beforeInsert?, beforeUpdate?, afterSave?, afterInsert?, and afterUpdate?, which do what you might expect. Method Signature
Parameters
Returns
ExamplesGiven a table named "people", suppose we wanted to automatically populate a field named "full_name" with the concatenation of the "first_name" and "last_name" fields. (Note you could also achieve a similar thing by making a calculated field for "full_name", but for this example, we assume that we actually want to store this in the database. We create a beforeSave() trigger that automatically updates the "full_name" field every time the record is saved. In the "people" table delegate class (i.e. tables/people/people.php)
See Alsoblog comments powered by Disqus |