尊龙凯时人生就是搏

ThinkPHP5.1ÖÐÔõôʵÏÖÔöɾ¸Ä²é²Ù×÷ÈÕÖ¾¼Í¼

Ò»¡¢ThinkPHP 5.1µÄÈÕÖ¾¼Í¼¹¦Ð§¼ò½é

ÔÚThinkPHP 5.1ÖУ¬ÈÕÖ¾¼Í¼¹¦Ð§ÒѾ­ÄÚÖá£ÎÒÃÇ¿ÉÒÔÔÚÓ¦ÓóÌÐòÖÐʹÓÃËüÀ´¼Í¼²î±ðÀàÐ͵ÄÊÂÎñ£¬ÖîÈç¹ýʧÐÂÎÅ¡¢µ÷ÊÔÐÅÏ¢ºÍÓû§²Ù×÷µÈ¡£Ëĸö¼¶±ðµÄÈÕÖ¾¼Í¼ÓÉ¿ò¼ÜÌṩ£¬»®·ÖΪ£ºDEBUG¡¢INFO¡¢NOTICEºÍERROR¡£

³ýÁËÄÚÖõÄÈÕÖ¾¼¶±ðÍ⣬ÎÒÃÇ»¹¿ÉÒÔ½ç˵×Ô¼ºµÄÈÕÖ¾¼¶±ð¡£ÎÒÃÇ¿ÉÒÔ¾ÙÀý˵Ã÷£¬½¨ÉèÒ»¸öÃûΪ¡°CRUD¡±µÄÈÕÖ¾¼¶±ð£¬ÒԼͼÔöɾ¸Ä²é²Ù×÷¡£

ÔÚĬÈÏÇéÐÎÏ£¬ÈÕÖ¾½«¼Í¼µ½Ó¦ÓóÌÐò¸ùĿ¼ÏµÄlogĿ¼ÖС£ÈôÊÇÐèÒª¸üËûÈÕÖ¾´æ´¢Î»Ö㬿ÉÒÔͨ¹ýÐÞ¸ÄÉèÖÃÎļþÀ´ÊµÏÖ¡£ÉèÖÃÎļþÒ»Ñùƽ³£Î»ÓÚÓ¦ÓóÌÐòµÄconfigĿ¼ÖС£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

¶þ¡¢Ôöɾ¸Ä²é²Ù×÷ÈÕÖ¾¼Í¼ʵÏÖ

ÎÒÃÇÀ´¿´¿´ÔõÑùÔÚThinkPHP 5.1ÖÐʵÏÖÔöɾ¸Ä²é²Ù×÷µÄÈÕÖ¾¼Í¼¡£ÎÒÃǽ«Æ¾Ö¤ÒÔÏ°취ʵÏÖ£º

ÔÚconfigĿ¼Öн¨Éè×Ô½ç˵ÉèÖÃÎļþ

ΪÊý¾Ý±íÌí¼ÓÈÕÖ¾×Ö¶Î

ÔÚModelÖÐÖØдÔöɾ¸ÄÒªÁì

¼Í¼ÈÕÖ¾

ÔÚconfigĿ¼Öн¨Éè×Ô½ç˵ÉèÖÃÎļþ

ÎÒÃÇÐèÒªÏȽ¨ÉèÒ»¸ö×Ô½ç˵ÉèÖÃÎļþ£¬·ÅÔÚÓ¦ÓóÌÐòµÄconfigĿ¼Ï¡£ÎÒÃÇ°ÑÕâ¸öÎļþÃüÃûΪcommon_extra.php¡£

$config = [

'crud_log' => true, // ¼Í¼Ôöɾ¸Ä²éÈÕÖ¾
'crud_ignore_fields' => ['create_time', 'update_time'] // ºöÂÔÈÕÖ¾¼Í¼µÄ×Ö¶Î

µÇ¼ºó¸´ÖÆ

];

ÔÚÉèÖÃÖУ¬ÎÒÃÇÉèÖÃÁËÁ½¸öÑ¡Ïî¡£µÚÒ»¸öÊÇcrud_log£¬ÓÃÓÚ¿ªÆô»ò¹Ø±ÕÈÕÖ¾¼Í¼¡£µÚ¶þ¸öÊÇcrud_ignore_fields£¬ÓÃÓÚÖ¸¶¨²»¼Í¼ÈÕÖ¾µÄ×ֶΡ£

ΪÊý¾Ý±íÌí¼ÓÈÕÖ¾×Ö¶Î

½ÓÏÂÀ´£¬ÎÒÃÇÐèҪΪÊý¾Ý±íÌí¼ÓһЩ×Ö¶ÎÀ´¼Í¼Ôöɾ¸Ä²é²Ù×÷¡£ÎÒÃÇ¿ÉÒÔΪÿ¸öÊý¾Ý±íÌí¼ÓÒÔÏÂ×ֶΣº

id£¨×ÔÔöÖ÷¼ü£©

user_id£¨²Ù×÷Óû§id£¬¿ÉΪ¿Õ£©

action£¨²Ù×÷ÀàÐÍ£¬ÈçÔöÌí¡¢É¾³ý¡¢Ð޸ģ©

table_name£¨²Ù×÷µÄÊý¾Ý±íÃû£©

data£¨²Ù×÷µÄÊý¾Ý£©

created_at£¨²Ù×÷ʱ¼ä£©

ÔÚModelÖÐÖØдÔöɾ¸ÄÒªÁì

ÏÖÔÚÎÒÃÇÐèÒªÔÚModelÖÐÖØдÔöɾ¸ÄÒªÁ죬ÒÔʵÏÖÈÕÖ¾¼Í¼¡£ÎÒÃǽ«Ê¹ÓÃÈ«¾ÖÅÌÎÊ×÷ÓÃÓòÀ´ÊµÏÖËü¡£ÎÒÃǽ«ÖØдcreate¡¢updateºÍdeleteÒªÁì¡£

ÔÚÿ¸öÒªÁìÖУ¬ÎÒÃǽ«¼Í¼ÏìÓ¦µÄ²Ù×÷ÀàÐͺÍÊý¾Ý¡£È»ºó£¬ÎÒÃǽ«Í¨¹ýʹÓÃÈÕÖ¾ÀཫÈÕ־дÈëÈÕÖ¾Îļþ¡£

ÒÔÏÂÊÇһЩʾÀý´úÂ룺

namespace app\common\model;

use think\Model;

class User extends Model

{

protected $table = 'users';

// Ìí¼ÓÈ«¾ÖÅÌÎʹæÄ£
protected static function init()
{
    // Ìí¼Ó²Ù×÷¼Í¼
    static::beforeInsert(function ($item) {
        if (config('common_extra.crud_log')) {
            $item->user_id = session('user_id');
            $item->action = 'add';
            $item->table_name = $this->table;
            $item->data = json_encode($item->toArray(), JSON_UNESCAPED_UNICODE);
            $item->created_at = date('Y-m-d H:i:s', time());
            Db::table('log')->insert($item->toArray());
        }
    });

    // Ð޸IJÙ×÷¼Í¼
    static::beforeUpdate(function ($item) {
        if (config('common_extra.crud_log')) {
            $item->user_id = session('user_id');
            $item->action = 'update';
            $item->table_name = $this->table;
            $item->data = json_encode($item->toArray(), JSON_UNESCAPED_UNICODE);
            $item->created_at = date('Y-m-d H:i:s', time());
            Db::table('log')->insert($item->toArray());
        }
    });

    // ɾ³ý²Ù×÷¼Í¼
    static::beforeDelete(function ($item) {
        if (config('common_extra.crud_log')) {
            $item->user_id = session('user_id');
            $item->action = 'delete';
            $item->table_name = $this->table;
            $item->data = json_encode($item->toArray(), JSON_UNESCAPED_UNICODE);
            $item->created_at = date('Y-m-d H:i:s', time());
            Db::table('log')->insert($item->toArray());
        }
    });
}

µÇ¼ºó¸´ÖÆ

}

¼Í¼ÈÕÖ¾

×îºó£¬ÎÒÃǽ«¼Í¼ÈÕÖ¾¡£ÔÚÇ°ÃæµÄʾÀýÖУ¬ÎÒÃǽ«ÈÕ־дÈëÃûΪ¡°log¡±µÄÊý¾Ý±íÖС£¿ÉÊÇ£¬Äú¿ÉÒÔƾ֤ÐèÒª½«ÈÕ־дÈëÎļþ£¬·¢Ë͸øÈÕ־ЧÀÍÆ÷»ò½«Æä·¢Ë͵½ÆäËûµØ·½¡£

ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇÀÖ³ÉʵÏÖÁËÔÚThinkPHP 5.1ÖжÔÔöɾ¸Ä²é²Ù×÷¾ÙÐÐÈÕÖ¾¼Í¼µÄ¹¦Ð§¡£

ÒÔÉϾÍÊÇThinkPHP5.1ÖÐÔõôʵÏÖÔöɾ¸Ä²é²Ù×÷ÈÕÖ¾¼Í¼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ