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

Source: Internet
Author: User
Related field: is_delete: False delete, whether to delete create_time: creation time update_time: Last update time tp version 3.2 when I want to process data through tp, perform the following operations: save is_delete0create_time creation time when adding data updat... related fields:
Is_delete
Create_time: creation time
Update_time: Last update time
Tp version 3.2
When I want to process data through tp, perform the following operations:

  • When adding data

    • Save is_delete = 0

    • Create_time = creation time

    • Update_time = creation time

  • When modifying [or deleting] data

    • Is_delete = 1 (1 indicates deletion)

    • Create_time = creation time

    • Update_time = current time

Every table operation must implement such a function. if every file is not written to death, what public methods should be implemented? How can this problem be achieved?

Reply content:

Related fields:
Is_delete
Create_time: creation time
Update_time: Last update time
Tp version 3.2
When I want to process data through tp, perform the following operations:

  • When adding data

    • Save is_delete = 0

    • Create_time = creation time

    • Update_time = creation time

  • When modifying [or deleting] data

    • Is_delete = 1 (1 indicates deletion)

    • Create_time = creation time

    • Update_time = current time

Every table operation must implement such a function. if every file is not written to death, what public methods should be implemented? How can this problem be achieved?

You need to use auto-completion in the model

Http://document.thinkphp1.cn/manual_3_2.html#auto_operate

Set the update_time type to timestamp and update it based on the current timestamp.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.