A field value in Thinkphp is a function used to increase or decrease the number of values.

Source: Internet
Author: User
In Thinkphp, a field value auto-increment or auto-increment function or a field value auto-incrementing function in Thinkphp, this function can be used for the page views of an article/** + ------------------------------------------------ auto-incrementing or auto-incrementing function of a field value in Thinkphp

The auto-increment or auto-incrementing function of a field value in Thinkphp can be used for the page views of the article.

/** + ---------------------- * Auto-increment or auto-increment of a field value + ------------------------ * @ access + -------------------- * @ param string $ model data table name * @ param string $ fields auto-increment or auto field name * @ param integer $ value auto increment or auto increment, the default value is 1 * @ param boolean $ type. the default value is true auto-increment, is false auto-subtract + -------------------- * @ return void + -------------------- */function autoed ($ id = '', $ model ='', $ fields = '', $ value = '', $ type = true) {if (! Empty ($ fields) {if (empty ($ model) {$ name = $ this-> getActionName () ;} else {$ name = $ model ;} $ model = M ($ name); // The default is the primary key ID $ pk = $ model-> getPk (); // The default Auto-increment and auto-increment values are 1 $ value =! Empty ($ value )? $ Value: 1; // if the default value is true, the value is auto-increment. if the value is false, the value is auto-increment. $ type = $ type? "Inc": "Dec"; switch ($ type) {case "Inc": $ model-> setInc ("$ fields", "$ pk = $ id ", $ value); break; case "Dec": $ model-> setDec ("$ fields", "$ pk = $ id", $ value ); $ list = $ model-> field ("$ fields")-> where ("$ pk = $ id")-> find (); if ($ list [$ fields] <= 0) {$ model-> where ("$ pk = $ id")-> setField ("$ fields", 0 );} break ;}}}
?

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.