回调
少于1分钟
Callbacks 回调
Pop provides a means to execute code before and after database operations. This is done by defining specific methods for your models.
Pop 提供了一种在数据库操作之前和之后执行代码的方法。这是通过为您的模型定义特定方法来完成的。
For example, to hash a user password you may want to define the following method:
例如,要对用户密码进行哈希处理,您可能需要定义以下方法:
|
|
In the above example, when the connection’s Save
method is called with a User
, the BeforeCreate
method will be called before writing to the database.
在上面的示例中,当连接的 Save
方法使用 User
调用时, BeforeCreate
方法将在写入数据库之前调用。
The available callbacks include:
可用的回调包括:
- BeforeSave
- BeforeCreate
- BeforeUpdate
- BeforeDestroy
- BeforeValidate
- AfterSave
- AfterCreate
- AfterUpdate
- AfterDestroy
- AfterFind
Related Content 相关内容
- Models - Define a database model. 模型 - 定义数据库模型。