{"id":23204,"date":"2024-11-21T09:59:39","date_gmt":"2024-11-21T01:59:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23204\/"},"modified":"2024-11-21T09:59:39","modified_gmt":"2024-11-21T01:59:39","slug":"thinkphp5-1%e4%b8%ad%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e6%93%8d%e4%bd%9c%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23204\/","title":{"rendered":"ThinkPHP5.1\u4e2d\u600e\u4e48\u5b9e\u73b0\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u65e5\u5fd7\u8bb0\u5f55"},"content":{"rendered":"<\/p>\n<p><strong>\u4e00\u3001ThinkPHP 5.1\u7684\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\u7b80\u4ecb<\/strong><\/p>\n<p>\u5728ThinkPHP 5.1\u4e2d\uff0c\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\u5df2\u7ecf\u5185\u7f6e\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5229\u7528\u5b83\u6765\u8bb0\u5f55\u4e0d\u540c\u7c7b\u578b\u7684\u4e8b\u4ef6\uff0c\u8bf8\u5982\u9519\u8bef\u6d88\u606f\u3001\u8c03\u8bd5\u4fe1\u606f\u548c\u7528\u6237\u64cd\u4f5c\u7b49\u3002\u56db\u4e2a\u7ea7\u522b\u7684\u65e5\u5fd7\u8bb0\u5f55\u7531\u6846\u67b6\u63d0\u4f9b\uff0c\u5206\u522b\u4e3a\uff1aDEBUG\u3001INFO\u3001NOTICE\u548cERROR\u3002<\/p>\n<p>\u9664\u4e86\u5185\u7f6e\u7684\u65e5\u5fd7\u7ea7\u522b\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u65e5\u5fd7\u7ea7\u522b\u3002\u6211\u4eec\u53ef\u4ee5\u4e3e\u4f8b\u8bf4\u660e\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cCRUD\u201d\u7684\u65e5\u5fd7\u7ea7\u522b\uff0c\u4ee5\u8bb0\u5f55\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002<\/p>\n<p>\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u65e5\u5fd7\u5c06\u8bb0\u5f55\u5230\u5e94\u7528\u7a0b\u5e8f\u6839\u76ee\u5f55\u4e0b\u7684log\u76ee\u5f55\u4e2d\u3002\u5982\u679c\u9700\u8981\u66f4\u6539\u65e5\u5fd7\u5b58\u50a8\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u6765\u5b9e\u73b0\u3002\u914d\u7f6e\u6587\u4ef6\u4e00\u822c\u4f4d\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684config\u76ee\u5f55\u4e2d\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u4e8c\u3001\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u65e5\u5fd7\u8bb0\u5f55\u5b9e\u73b0<\/strong><\/p>\n<p>\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u5728ThinkPHP 5.1\u4e2d\u5b9e\u73b0\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u6211\u4eec\u5c06\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<ol>\n<li>\n<p>\u5728config\u76ee\u5f55\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u6570\u636e\u8868\u6dfb\u52a0\u65e5\u5fd7\u5b57\u6bb5<\/p>\n<\/li>\n<li>\n<p>\u5728Model\u4e2d\u91cd\u5199\u589e\u5220\u6539\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u8bb0\u5f55\u65e5\u5fd7<\/p>\n<\/li>\n<li>\n<p>\u5728config\u76ee\u5f55\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6<\/p>\n<\/li>\n<\/ol>\n<p>\u6211\u4eec\u9700\u8981\u5148\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\uff0c\u653e\u5728\u5e94\u7528\u7a0b\u5e8f\u7684config\u76ee\u5f55\u4e0b\u3002\u6211\u4eec\u628a\u8fd9\u4e2a\u6587\u4ef6\u547d\u540d\u4e3acommon_extra.php\u3002<\/p>\n<p>$config = [<\/p>\n<pre>'crud_log'&nbsp;=&amp;gt;&nbsp;true,&nbsp;\/\/&nbsp;\u8bb0\u5f55\u589e\u5220\u6539\u67e5\u65e5\u5fd7\n'crud_ignore_fields'&nbsp;=&amp;gt;&nbsp;['create_time',&nbsp;'update_time']&nbsp;\/\/&nbsp;\u5ffd\u7565\u65e5\u5fd7\u8bb0\u5f55\u7684\u5b57\u6bb5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>];<\/p>\n<p>\u5728\u914d\u7f6e\u4e2d\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e86\u4e24\u4e2a\u9009\u9879\u3002\u7b2c\u4e00\u4e2a\u662fcrud_log\uff0c\u7528\u4e8e\u5f00\u542f\u6216\u5173\u95ed\u65e5\u5fd7\u8bb0\u5f55\u3002\u7b2c\u4e8c\u4e2a\u662fcrud_ignore_fields\uff0c\u7528\u4e8e\u6307\u5b9a\u4e0d\u8bb0\u5f55\u65e5\u5fd7\u7684\u5b57\u6bb5\u3002<\/p>\n<ol>\n<li>\n<p>\u4e3a\u6570\u636e\u8868\u6dfb\u52a0\u65e5\u5fd7\u5b57\u6bb5<\/p>\n<\/li>\n<\/ol>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u6570\u636e\u8868\u6dfb\u52a0\u4e00\u4e9b\u5b57\u6bb5\u6765\u8bb0\u5f55\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002\u6211\u4eec\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u6570\u636e\u8868\u6dfb\u52a0\u4ee5\u4e0b\u5b57\u6bb5\uff1a<\/p>\n<ol>\n<li>\n<p>id\uff08\u81ea\u589e\u4e3b\u952e\uff09<\/p>\n<\/li>\n<li>\n<p>user_id\uff08\u64cd\u4f5c\u7528\u6237id\uff0c\u53ef\u4e3a\u7a7a\uff09<\/p>\n<\/li>\n<li>\n<p>action\uff08\u64cd\u4f5c\u7c7b\u578b\uff0c\u5982\u589e\u52a0\u3001\u5220\u9664\u3001\u4fee\u6539\uff09<\/p>\n<\/li>\n<li>\n<p>table_name\uff08\u64cd\u4f5c\u7684\u6570\u636e\u8868\u540d\uff09<\/p>\n<\/li>\n<li>\n<p>data\uff08\u64cd\u4f5c\u7684\u6570\u636e\uff09<\/p>\n<\/li>\n<li>\n<p>created_at\uff08\u64cd\u4f5c\u65f6\u95f4\uff09<\/p>\n<\/li>\n<li>\n<p>\u5728Model\u4e2d\u91cd\u5199\u589e\u5220\u6539\u65b9\u6cd5<\/p>\n<\/li>\n<\/ol>\n<p>\u73b0\u5728\u6211\u4eec\u9700\u8981\u5728Model\u4e2d\u91cd\u5199\u589e\u5220\u6539\u65b9\u6cd5\uff0c\u4ee5\u5b9e\u73b0\u65e5\u5fd7\u8bb0\u5f55\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u5168\u5c40\u67e5\u8be2\u4f5c\u7528\u57df\u6765\u5b9e\u73b0\u5b83\u3002\u6211\u4eec\u5c06\u91cd\u5199create\u3001update\u548cdelete\u65b9\u6cd5\u3002<\/p>\n<p>\u5728\u6bcf\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u5c06\u8bb0\u5f55\u76f8\u5e94\u7684\u64cd\u4f5c\u7c7b\u578b\u548c\u6570\u636e\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u4f7f\u7528\u65e5\u5fd7\u7c7b\u5c06\u65e5\u5fd7\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<p>namespace appcommonmodel;<\/p>\n<p>use thinkModel;<\/p>\n<p>class User extends Model<br \/>{<\/p>\n<pre>protected&nbsp;$table&nbsp;=&nbsp;'users';\n\n\/\/&nbsp;\u6dfb\u52a0\u5168\u5c40\u67e5\u8be2\u8303\u56f4\nprotected&nbsp;static&nbsp;function&nbsp;init()\n{\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6dfb\u52a0\u64cd\u4f5c\u8bb0\u5f55\n&nbsp;&nbsp;&nbsp;&nbsp;static::beforeInsert(function&nbsp;($item)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(config('common_extra.crud_log'))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;user_id&nbsp;=&nbsp;session('user_id');\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;action&nbsp;=&nbsp;'add';\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;table_name&nbsp;=&nbsp;$this-&amp;gt;table;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;data&nbsp;=&nbsp;json_encode($item-&amp;gt;toArray(),&nbsp;JSON_UNESCAPED_UNICODE);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;created_at&nbsp;=&nbsp;date('Y-m-d&nbsp;H:i:s',&nbsp;time());\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Db::table('log')-&amp;gt;insert($item-&amp;gt;toArray());\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;});\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u4fee\u6539\u64cd\u4f5c\u8bb0\u5f55\n&nbsp;&nbsp;&nbsp;&nbsp;static::beforeUpdate(function&nbsp;($item)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(config('common_extra.crud_log'))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;user_id&nbsp;=&nbsp;session('user_id');\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;action&nbsp;=&nbsp;'update';\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;table_name&nbsp;=&nbsp;$this-&amp;gt;table;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;data&nbsp;=&nbsp;json_encode($item-&amp;gt;toArray(),&nbsp;JSON_UNESCAPED_UNICODE);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;created_at&nbsp;=&nbsp;date('Y-m-d&nbsp;H:i:s',&nbsp;time());\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Db::table('log')-&amp;gt;insert($item-&amp;gt;toArray());\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;});\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u5220\u9664\u64cd\u4f5c\u8bb0\u5f55\n&nbsp;&nbsp;&nbsp;&nbsp;static::beforeDelete(function&nbsp;($item)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(config('common_extra.crud_log'))&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;user_id&nbsp;=&nbsp;session('user_id');\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;action&nbsp;=&nbsp;'delete';\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;table_name&nbsp;=&nbsp;$this-&amp;gt;table;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;data&nbsp;=&nbsp;json_encode($item-&amp;gt;toArray(),&nbsp;JSON_UNESCAPED_UNICODE);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;created_at&nbsp;=&nbsp;date('Y-m-d&nbsp;H:i:s',&nbsp;time());\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Db::table('log')-&amp;gt;insert($item-&amp;gt;toArray());\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;});\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>}<\/p>\n<ol>\n<li>\n<p>\u8bb0\u5f55\u65e5\u5fd7<\/p>\n<\/li>\n<\/ol>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u5c06\u8bb0\u5f55\u65e5\u5fd7\u3002\u5728\u524d\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u65e5\u5fd7\u5199\u5165\u540d\u4e3a\u201clog\u201d\u7684\u6570\u636e\u8868\u4e2d\u3002\u4f46\u662f\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5c06\u65e5\u5fd7\u5199\u5165\u6587\u4ef6\uff0c\u53d1\u9001\u7ed9\u65e5\u5fd7\u670d\u52a1\u5668\u6216\u5c06\u5176\u53d1\u9001\u5230\u5176\u4ed6\u5730\u65b9\u3002<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u6210\u529f\u5b9e\u73b0\u4e86\u5728ThinkPHP 5.1\u4e2d\u5bf9\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u8fdb\u884c\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fThinkPHP5.1\u4e2d\u600e\u4e48\u5b9e\u73b0\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u65e5\u5fd7\u8bb0\u5f55\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001ThinkPHP 5.1\u7684\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\u7b80\u4ecb \u5728ThinkPHP 5.1\u4e2d\uff0c\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\u5df2\u7ecf\u5185\u7f6e\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5229\u7528\u5b83\u6765\u8bb0\u5f55\u4e0d\u540c\u7c7b\u578b\u7684\u4e8b\u4ef6\uff0c\u8bf8\u5982\u9519\u8bef\u6d88\u606f\u3001\u8c03\u8bd5\u4fe1\u606f\u548c\u7528\u6237\u64cd\u4f5c\u7b49\u3002\u56db\u4e2a\u7ea7\u522b\u7684\u65e5\u5fd7\u8bb0\u5f55\u7531\u6846\u67b6\u63d0\u4f9b\uff0c\u5206\u522b\u4e3a\uff1aDEBUG\u3001INFO\u3001NOTICE\u548cERROR\u3002 \u9664\u4e86\u5185\u7f6e\u7684\u65e5\u5fd7\u7ea7\u522b\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u65e5\u5fd7\u7ea7\u522b\u3002\u6211\u4eec\u53ef\u4ee5\u4e3e\u4f8b\u8bf4\u660e\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cCRUD\u201d\u7684\u65e5\u5fd7\u7ea7\u522b\uff0c\u4ee5\u8bb0\u5f55\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002 \u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u65e5\u5fd7\u5c06\u8bb0\u5f55\u5230\u5e94\u7528\u7a0b\u5e8f\u6839\u76ee\u5f55\u4e0b\u7684log\u76ee\u5f55\u4e2d\u3002\u5982\u679c\u9700\u8981\u66f4\u6539\u65e5\u5fd7\u5b58\u50a8\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u6765\u5b9e\u73b0\u3002\u914d\u7f6e\u6587\u4ef6\u4e00\u822c\u4f4d\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684config\u76ee\u5f55\u4e2d\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4e8c\u3001\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u65e5\u5fd7\u8bb0\u5f55\u5b9e\u73b0 \u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u5728ThinkPHP 5.1\u4e2d\u5b9e\u73b0\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u6211\u4eec\u5c06\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a \u5728config\u76ee\u5f55\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6 \u4e3a\u6570\u636e\u8868\u6dfb\u52a0\u65e5\u5fd7\u5b57\u6bb5 \u5728Model\u4e2d\u91cd\u5199\u589e\u5220\u6539\u65b9\u6cd5 \u8bb0\u5f55\u65e5\u5fd7 \u5728config\u76ee\u5f55\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6 \u6211\u4eec\u9700\u8981\u5148\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\uff0c\u653e\u5728\u5e94\u7528\u7a0b\u5e8f\u7684config\u76ee\u5f55\u4e0b\u3002\u6211\u4eec\u628a\u8fd9\u4e2a\u6587\u4ef6\u547d\u540d\u4e3acommon_extra.php\u3002 $config = [ &#8216;crud_log&#8217;&nbsp;=&amp;gt;&nbsp;true,&nbsp;\/\/&nbsp;\u8bb0\u5f55\u589e\u5220\u6539\u67e5\u65e5\u5fd7 &#8216;crud_ignore_fields&#8217;&nbsp;=&amp;gt;&nbsp;[&#8216;create_time&#8217;,&nbsp;&#8216;update_time&#8217;]&nbsp;\/\/&nbsp;\u5ffd\u7565\u65e5\u5fd7\u8bb0\u5f55\u7684\u5b57\u6bb5 \u767b\u5f55\u540e\u590d\u5236 ]; \u5728\u914d\u7f6e\u4e2d\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e86\u4e24\u4e2a\u9009\u9879\u3002\u7b2c\u4e00\u4e2a\u662fcrud_log\uff0c\u7528\u4e8e\u5f00\u542f\u6216\u5173\u95ed\u65e5\u5fd7\u8bb0\u5f55\u3002\u7b2c\u4e8c\u4e2a\u662fcrud_ignore_fields\uff0c\u7528\u4e8e\u6307\u5b9a\u4e0d\u8bb0\u5f55\u65e5\u5fd7\u7684\u5b57\u6bb5\u3002 \u4e3a\u6570\u636e\u8868\u6dfb\u52a0\u65e5\u5fd7\u5b57\u6bb5 \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u6570\u636e\u8868\u6dfb\u52a0\u4e00\u4e9b\u5b57\u6bb5\u6765\u8bb0\u5f55\u589e\u5220\u6539\u67e5\u64cd\u4f5c\u3002\u6211\u4eec\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u6570\u636e\u8868\u6dfb\u52a0\u4ee5\u4e0b\u5b57\u6bb5\uff1a id\uff08\u81ea\u589e\u4e3b\u952e\uff09 user_id\uff08\u64cd\u4f5c\u7528\u6237id\uff0c\u53ef\u4e3a\u7a7a\uff09 action\uff08\u64cd\u4f5c\u7c7b\u578b\uff0c\u5982\u589e\u52a0\u3001\u5220\u9664\u3001\u4fee\u6539\uff09 table_name\uff08\u64cd\u4f5c\u7684\u6570\u636e\u8868\u540d\uff09 data\uff08\u64cd\u4f5c\u7684\u6570\u636e\uff09 created_at\uff08\u64cd\u4f5c\u65f6\u95f4\uff09 \u5728Model\u4e2d\u91cd\u5199\u589e\u5220\u6539\u65b9\u6cd5 \u73b0\u5728\u6211\u4eec\u9700\u8981\u5728Model\u4e2d\u91cd\u5199\u589e\u5220\u6539\u65b9\u6cd5\uff0c\u4ee5\u5b9e\u73b0\u65e5\u5fd7\u8bb0\u5f55\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u5168\u5c40\u67e5\u8be2\u4f5c\u7528\u57df\u6765\u5b9e\u73b0\u5b83\u3002\u6211\u4eec\u5c06\u91cd\u5199create\u3001update\u548cdelete\u65b9\u6cd5\u3002 \u5728\u6bcf\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u5c06\u8bb0\u5f55\u76f8\u5e94\u7684\u64cd\u4f5c\u7c7b\u578b\u548c\u6570\u636e\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u4f7f\u7528\u65e5\u5fd7\u7c7b\u5c06\u65e5\u5fd7\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\u3002 \u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u4ee3\u7801\uff1a namespace appcommonmodel; use thinkModel; class User extends Model{ protected&nbsp;$table&nbsp;=&nbsp;&#8216;users&#8217;; \/\/&nbsp;\u6dfb\u52a0\u5168\u5c40\u67e5\u8be2\u8303\u56f4 protected&nbsp;static&nbsp;function&nbsp;init() { &nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;\u6dfb\u52a0\u64cd\u4f5c\u8bb0\u5f55 &nbsp;&nbsp;&nbsp;&nbsp;static::beforeInsert(function&nbsp;($item)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(config(&#8216;common_extra.crud_log&#8217;))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;user_id&nbsp;=&nbsp;session(&#8216;user_id&#8217;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;action&nbsp;=&nbsp;&#8216;add&#8217;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;table_name&nbsp;=&nbsp;$this-&amp;gt;table; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$item-&amp;gt;data&nbsp;=&nbsp;json_encode($item-&amp;gt;toArray(),&nbsp;JSON_UNESCAPED_UNICODE); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-23204","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=23204"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23204\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}