-
Notifications
You must be signed in to change notification settings - Fork 1.9k
docs: improve Model Event #8324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14c3045
docs: add missing "method"
kenjis 2e7399a
docs: improve readability
kenjis fe884ad
docs: remove unneeded row
kenjis 7fdc425
docs: decorate method names
kenjis c04a4e7
docs: make `id` clearer
kenjis 97c4518
docs: just joining lines together nicely
kenjis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -738,12 +738,20 @@ points in the model's execution can be affected, each through a class property: | |||||||
Defining Callbacks | ||||||||
================== | ||||||||
|
||||||||
You specify the callbacks by first creating a new class method in your model to use. This class will always | ||||||||
receive a ``$data`` array as its only parameter. The exact contents of the ``$data`` array will vary between events, but | ||||||||
will always contain a key named **data** that contains the primary data passed to the original method. In the case | ||||||||
of the insert* or update* methods, that will be the key/value pairs that are being inserted into the database. The | ||||||||
main array will also contain the other values passed to the method, and be detailed later. The callback method | ||||||||
must return the original $data array so other callbacks have the full information. | ||||||||
You specify the callbacks by first creating a new class method in your model to use. | ||||||||
|
||||||||
This class method will always | ||||||||
receive a ``$data`` array as its only parameter. | ||||||||
|
||||||||
The exact contents of the ``$data`` array will vary between events, but | ||||||||
will always contain a key named ``data`` that contains the primary data passed to the original method. | ||||||||
In the case | ||||||||
of the **insert*()** or **update*()** methods, that will be the key/value pairs that are being inserted into the database. | ||||||||
The | ||||||||
main ``$data`` array will also contain the other values passed to the method, and be detailed in `Event Parameters`_. | ||||||||
|
||||||||
The callback method | ||||||||
must return the original ``$data`` array so other callbacks have the full information. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
.. literalinclude:: model/050.php | ||||||||
|
||||||||
|
@@ -774,37 +782,36 @@ passed to each event: | |||||||
Event $data contents | ||||||||
================= ========================================================================================================= | ||||||||
beforeInsert **data** = the key/value pairs that are being inserted. If an object or Entity class is passed to the | ||||||||
insert method, it is first converted to an array. | ||||||||
``insert()`` method, it is first converted to an array. | ||||||||
afterInsert **id** = the primary key of the new row, or 0 on failure. | ||||||||
**data** = the key/value pairs being inserted. | ||||||||
**result** = the results of the insert() method used through the Query Builder. | ||||||||
**result** = the results of the ``insert()`` method used through the Query Builder. | ||||||||
beforeUpdate **id** = the array of primary keys of the rows being updated. | ||||||||
**data** = the key/value pairs that are being updated. If an object or Entity class is passed to the | ||||||||
update method, it is first converted to an array. | ||||||||
``update()`` method, it is first converted to an array. | ||||||||
afterUpdate **id** = the array of primary keys of the rows being updated. | ||||||||
**data** = the key/value pairs being updated. | ||||||||
**result** = the results of the update() method used through the Query Builder. | ||||||||
**result** = the results of the ``update()`` method used through the Query Builder. | ||||||||
beforeFind The name of the calling **method**, whether a **singleton** was requested, and these additional fields: | ||||||||
- first() No additional fields | ||||||||
- find() **id** = the primary key of the row being searched for. | ||||||||
- findAll() **limit** = the number of rows to find. | ||||||||
- ``first()`` No additional fields | ||||||||
- ``find()`` **id** = the primary key of the row being searched for. | ||||||||
- ``findAll()`` **limit** = the number of rows to find. | ||||||||
**offset** = the number of rows to skip during the search. | ||||||||
afterFind Same as **beforeFind** but including the resulting row(s) of data, or null if no result found. | ||||||||
beforeDelete Varies by delete* method. See the following: | ||||||||
- delete() **id** = primary key of row being deleted. | ||||||||
beforeDelete **id** = primary key of row being passed to the ``delete()`` method. | ||||||||
**purge** = boolean whether soft-delete rows should be hard deleted. | ||||||||
afterDelete **id** = primary key of row being deleted. | ||||||||
afterDelete **id** = primary key of row being passed to the ``delete()`` method. | ||||||||
**purge** = boolean whether soft-delete rows should be hard deleted. | ||||||||
**result** = the result of the delete() call on the Query Builder. | ||||||||
**result** = the result of the ``delete()`` call on the Query Builder. | ||||||||
**data** = unused. | ||||||||
beforeInsertBatch **data** = associative array of values that are being inserted. If an object or Entity class is passed to the | ||||||||
insertBatch method, it is first converted to an array. | ||||||||
``insertBatch()`` method, it is first converted to an array. | ||||||||
afterInsertBatch **data** = the associative array of values being inserted. | ||||||||
**result** = the results of the insertbatch() method used through the Query Builder. | ||||||||
**result** = the results of the ``insertbatch()`` method used through the Query Builder. | ||||||||
beforeUpdateBatch **data** = associative array of values that are being updated. If an object or Entity class is passed to the | ||||||||
updateBatch method, it is first converted to an array. | ||||||||
``updateBatch()`` method, it is first converted to an array. | ||||||||
afterUpdateBatch **data** = the key/value pairs being updated. | ||||||||
**result** = the results of the updateBatch() method used through the Query Builder. | ||||||||
**result** = the results of the ``updateBatch()`` method used through the Query Builder. | ||||||||
================= ========================================================================================================= | ||||||||
|
||||||||
Modifying Find* Data | ||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just joining lines together nicely. Not sure if you meant those to be two paragraphs or one, so adjust as desired.