{"id":2510,"date":"2024-11-10T13:34:40","date_gmt":"2024-11-10T05:34:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2510\/"},"modified":"2024-11-10T13:34:40","modified_gmt":"2024-11-10T05:34:40","slug":"yii-%e4%b8%ad%e7%9a%84-confirm-%e9%80%89%e9%a1%b9%e4%b8%ba%e4%bb%80%e4%b9%88%e6%9c%89%e6%97%b6%e5%80%99%e4%b8%8d%e4%bc%9a%e5%bc%b9%e5%87%ba%e5%bc%b9%e6%a1%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2510\/","title":{"rendered":"Yii \u4e2d\u7684 confirm \u9009\u9879\u4e3a\u4ec0\u4e48\u6709\u65f6\u5019\u4e0d\u4f1a\u5f39\u51fa\u5f39\u6846\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173078030145558.jpg\" class=\"aligncenter\" title=\"Yii \u4e2d\u7684 confirm \u9009\u9879\u4e3a\u4ec0\u4e48\u6709\u65f6\u5019\u4e0d\u4f1a\u5f39\u51fa\u5f39\u6846\uff1f\u63d2\u56fe\" alt=\"Yii \u4e2d\u7684 confirm \u9009\u9879\u4e3a\u4ec0\u4e48\u6709\u65f6\u5019\u4e0d\u4f1a\u5f39\u51fa\u5f39\u6846\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>yii confirm \u672a\u5f39\u51fa\u5f39\u6846\uff0c\u800c\u662f\u76f4\u63a5\u6267\u884c\u540e\u7eed\u4ee3\u7801\u7684\u539f\u56e0<\/strong><\/p>\n<p>yii \u4e2d\u7684 confirm \u9009\u9879\u7528\u4e8e\u5728\u6267\u884c\u52a8\u4f5c\u524d\u663e\u793a\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u8be5\u5f39\u6846\u53ef\u80fd\u65e0\u6cd5\u5f39\u51fa\uff0c\u5bfc\u81f4\u4ee3\u7801\u76f4\u63a5\u6267\u884c\u540e\u7eed\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u53ef\u80fd\u5bfc\u81f4\u6b64\u95ee\u9898\u7684\u4e00\u4e9b\u539f\u56e0\uff1a<\/p>\n<p><strong>1. \u7f3a\u5c11\u4f9d\u8d56\u5173\u7cfb<\/strong><\/p>\n<p>\u786e\u4fdd\u5df2\u5305\u62ec\u4e86 yiijuijuiasset \u4f9d\u8d56\u5173\u7cfb\u3002\u6b64\u4f9d\u8d56\u5173\u7cfb\u63d0\u4f9b\u5fc5\u8981\u7684 javascript \u811a\u672c\u4ee5\u5904\u7406\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002<\/p>\n<p><strong>2. \u9519\u8bef\u7684\u6309\u94ae<\/strong><\/p>\n<p>\u786e\u8ba4\u5bf9\u8bdd\u6846\u5e94\u5305\u542b\u4e24\u4e2a\u6309\u94ae\uff1a<\/p>\n<ul>\n<li>\u786e\u8ba4\u6309\u94ae\uff08\u901a\u5e38\u4e3a\u201c\u786e\u5b9a\u201d\uff09<\/li>\n<li>\u53d6\u6d88\u6309\u94ae\uff08\u901a\u5e38\u4e3a\u201c\u53d6\u6d88\u201d\uff09<\/li>\n<\/ul>\n<p>\u786e\u4fdd\u5df2\u6b63\u786e\u5b9a\u4e49\u4e86\u8fd9\u4e24\u4e2a\u6309\u94ae\u3002<\/p>\n<p><strong>3. ajax \u8bf7\u6c42<\/strong><\/p>\n<p>\u5982\u679c\u8981\u901a\u8fc7 ajax \u8bf7\u6c42\u89e6\u53d1\u64cd\u4f5c\uff0c\u8bf7\u786e\u4fdd ajax \u8bf7\u6c42\u5df2\u6b63\u786e\u914d\u7f6e\u4e3a\u663e\u793a\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002\u8bf7\u4f7f\u7528 yiihelpersurl::to \u751f\u6210\u6240\u9700\u7684 ajax url\uff0c\u5176\u4e2d\u5305\u542b &#8216;data-confirm&#8217; \u53c2\u6570\u3002<\/p>\n<p><strong>4. \u7981\u6b62 javascript<\/strong><\/p>\n<p>\u5982\u679c\u5728\u6d4f\u89c8\u5668\u4e2d\u7981\u7528\u4e86 javascript\uff0c\u786e\u8ba4\u5bf9\u8bdd\u6846\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\u3002\u8bf7\u786e\u4fdd\u5df2\u542f\u7528 javascript\u3002<\/p>\n<p><strong>5. \u4ee3\u7801\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 confirm \u9009\u9879\u7684\u66f4\u65b0\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>use yiihelpersHtml;\n\necho Html::a('\u5220\u9664', ['post\/delete', 'id' =&gt; $post['id']], ['data-confirm' =&gt; '\u786e\u5b9a\u8981\u5220\u9664\u5417\uff1f']);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u89e3\u51b3\u4e0a\u8ff0\u95ee\u9898\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd yii \u4e2d\u7684 confirm \u9009\u9879\u6b63\u5e38\u5de5\u4f5c\uff0c\u4ece\u800c\u5728\u6267\u884c\u52a8\u4f5c\u524d\u59cb\u7ec8\u663e\u793a\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fYii \u4e2d\u7684 confirm \u9009\u9879\u4e3a\u4ec0\u4e48\u6709\u65f6\u5019\u4e0d\u4f1a\u5f39\u51fa\u5f39\u6846\uff1f\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>yii confirm \u672a\u5f39\u51fa\u5f39\u6846\uff0c\u800c\u662f\u76f4\u63a5\u6267\u884c\u540e\u7eed\u4ee3\u7801\u7684\u539f\u56e0 yii \u4e2d\u7684 confirm \u9009\u9879\u7528\u4e8e\u5728\u6267\u884c\u52a8\u4f5c\u524d\u663e\u793a\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u8be5\u5f39\u6846\u53ef\u80fd\u65e0\u6cd5\u5f39\u51fa\uff0c\u5bfc\u81f4\u4ee3\u7801\u76f4\u63a5\u6267\u884c\u540e\u7eed\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u53ef\u80fd\u5bfc\u81f4\u6b64\u95ee\u9898\u7684\u4e00\u4e9b\u539f\u56e0\uff1a 1. \u7f3a\u5c11\u4f9d\u8d56\u5173\u7cfb \u786e\u4fdd\u5df2\u5305\u62ec\u4e86 yiijuijuiasset \u4f9d\u8d56\u5173\u7cfb\u3002\u6b64\u4f9d\u8d56\u5173\u7cfb\u63d0\u4f9b\u5fc5\u8981\u7684 javascript \u811a\u672c\u4ee5\u5904\u7406\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002 2. \u9519\u8bef\u7684\u6309\u94ae \u786e\u8ba4\u5bf9\u8bdd\u6846\u5e94\u5305\u542b\u4e24\u4e2a\u6309\u94ae\uff1a \u786e\u8ba4\u6309\u94ae\uff08\u901a\u5e38\u4e3a\u201c\u786e\u5b9a\u201d\uff09 \u53d6\u6d88\u6309\u94ae\uff08\u901a\u5e38\u4e3a\u201c\u53d6\u6d88\u201d\uff09 \u786e\u4fdd\u5df2\u6b63\u786e\u5b9a\u4e49\u4e86\u8fd9\u4e24\u4e2a\u6309\u94ae\u3002 3. ajax \u8bf7\u6c42 \u5982\u679c\u8981\u901a\u8fc7 ajax \u8bf7\u6c42\u89e6\u53d1\u64cd\u4f5c\uff0c\u8bf7\u786e\u4fdd ajax \u8bf7\u6c42\u5df2\u6b63\u786e\u914d\u7f6e\u4e3a\u663e\u793a\u786e\u8ba4\u5bf9\u8bdd\u6846\u3002\u8bf7\u4f7f\u7528 yiihelpersurl::to \u751f\u6210\u6240\u9700\u7684 ajax url\uff0c\u5176\u4e2d\u5305\u542b &#8216;data-confirm&#8217; \u53c2\u6570\u3002 4. \u7981\u6b62 javascript \u5982\u679c\u5728\u6d4f\u89c8\u5668\u4e2d\u7981\u7528\u4e86 javascript\uff0c\u786e\u8ba4\u5bf9\u8bdd\u6846\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\u3002\u8bf7\u786e\u4fdd\u5df2\u542f\u7528 javascript\u3002 5. \u4ee3\u7801\u793a\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 confirm \u9009\u9879\u7684\u66f4\u65b0\u7684\u4ee3\u7801\u793a\u4f8b\uff1a use yiihelpersHtml; echo Html::a(&#8216;\u5220\u9664&#8217;, [&#8216;post\/delete&#8217;, &#8216;id&#8217; =&gt; $post[&#8216;id&#8217;]], [&#8216;data-confirm&#8217; =&gt; [&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-2510","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2510","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=2510"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2510\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}