Home > Backend Development > PHP Tutorial > How can I save the operation time when Thinkphp modifies data?

How can I save the operation time when Thinkphp modifies data?

WBOY
Release: 2016-07-06 13:52:25
Original
1489 people have browsed it

Related fields:
is_delete: false deletion, whether it has been deleted
create_time: creation time
update_time: last update time
tp version 3.2
I hope to process the data through tp , perform the following operations:

  • When adding new data

    • Save is_delete=0

    • create_time=Creation time

    • update_time=creation time

  • When modifying [or deleting] data

    • is_delete=1 (1 means delete)

    • create_time=Creation time

    • update_time=current time

Each table operation must implement such a function. It would be unscientific if each file is hard-coded. Should there be some public method? How to achieve this?

Reply content:

Related fields:
is_delete: false deletion, whether it has been deleted
create_time: creation time
update_time: last update time
tp version 3.2
I hope to process the data through tp , perform the following operations:

  • When adding new data

    • Save is_delete=0

    • create_time=Creation time

    • update_time=creation time

  • When modifying [or deleting] data

    • is_delete=1 (1 means delete)

    • create_time=Creation time

    • update_time=current time

Each table operation must implement such a function. It would be unscientific if each file is hard-coded. Should there be some public method? How to achieve this?

You need to use autocomplete in your model

http://document.thinkphp.cn/manual_3_2.html#auto_operate

Directly set the type of update_time to timestamp and update it based on the current timestamp

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template