thinkphp5¹Ø±ÕÒ³Ãæ
˼Ë÷php5¹Ø±ÕÒ³ÃæµÄÒªÁì
ÔÚ¿ª·¢WebÓ¦ÓóÌÐòʱ£¬Äú¿ÉÄÜÐèÒªÔÚijЩÇéÐÎϹرÕÒ³Ãæ¡£ÀýÈ磬µ±Óû§ÀÖ³ÉÌá½»±íµ¥»òÖ´ÐÐijЩ²Ù×÷ºó£¬¿ÉÄÜÐèÒª¹Ø±ÕÒ³Ãæ¡£ÔÚÕâÖÖÇéÐÎÏ£¬ÄúÐèÒªÏòÓû§·¢ËÍÒ»ÌõÐÂÎÅ£¬¸æËßËûÃDzÙ×÷ÒÑÀÖ³ÉÍê³É£¬²¢¹Ø±ÕÄ¿½ñÒ³Ãæ¡£¹ØÓÚÐí¶àWeb¿ª·¢Ö°Ô±¶øÑÔ£¬¹Ø±ÕÒ³ÃæÊÇÒ»ÏîºÜÊÇÖ÷ÒªÇÒ³£¼ûµÄʹÃü¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÔÚThinkPHP5¿ò¼ÜÏÂʵÏֹرÕÒ³ÃæµÄÒªÁì¡£
1.ʹÓÃJavaScriptʵÏֹرÕÒ³Ãæ
×î³£¼ûµÄ¹Ø±ÕÒ³ÃæÒªÁìÊÇʹÓÃJavaScript¡£JavaScriptÊÇÒ»ÖÖ¿Í»§¶Ë¾ç±¾ÓïÑÔ£¬¿ÉÒÔÔÚÓû§ä¯ÀÀÆ÷ÖÐÖ´ÐУ¬×ÊÖúÄú½¨É趯̬WebÓ¦ÓóÌÐò¡£ËüµÄÒ»¸öÓŵãÊÇ¿ÉÒÔÔÚ¿Í»§¶Ë¹Ø±Õ´°¿Ú»òä¯ÀÀÆ÷¡£ÒÔÏÂÊÇÒ»¸öJavaScriptº¯Êý£¬¿ÉÒÔ×ÊÖúÄúÔÚThinkPHP5ÖйرÕÒ³Ã棺
function close_window() { if (confirm("ÊÇ·ñ¹Ø±Õ´°¿Ú£¿")) { close(); } }
µÇ¼ºó¸´ÖÆ
ÔÚViewÖУ¬Äú¿ÉÒÔ½«´Ëº¯ÊýǶÈëµ½ÄúµÄHTML´úÂëÖУ¬ÈçÏÂËùʾ£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
<a href="javascript:close_window()">¹Ø±ÕÒ³Ãæ</a>
µÇ¼ºó¸´ÖÆ
µ±Óû§µ¥»÷¡°¹Ø±ÕÒ³Ã桱Á´½Óʱ£¬½«ÏÔʾһ¸öÈ·ÈÏ¿ò£¬Ñ¯ÎÊÓû§ÊÇ·ñ¹Ø±Õ´°¿Ú¡£ÈôÊÇÓû§µ¥»÷¡°È·ÈÏ¡±°´Å¥£¬ÔòÒ³Ã潫¹Ø±Õ¡£
2.ʹÓÃPHP´úÂëʵÏֹرÕÒ³Ãæ
³ýÁËJavaScriptÖ®Í⣬Äú»¹¿ÉÒÔʹÓÃPHP´úÂëÀ´¹Ø±ÕÒ³Ãæ¡£ÔÚThinkPHP5¿ò¼ÜÏ£¬¿ÉÒÔʹÓÃPHPµÄHeaderº¯ÊýÀ´ÊµÏÖ´ËÄ¿µÄ¡£Headerº¯ÊýÓÃÓÚÏò¿Í»§¶Ëä¯ÀÀÆ÷·¢ËÍHTTPÍ·¡£Äú¿ÉÒÔʹÓô˺¯ÊýÏò¿Í»§¶Ëä¯ÀÀÆ÷·¢ËÍÒ»¸öÖ¸ÁָÁî¸æËßä¯ÀÀÆ÷¹Ø±Õ´°¿Ú»òä¯ÀÀÆ÷¡£ÒÔÏÂÊÇʹÓÃHeaderº¯Êý¹Ø±ÕÒ³ÃæµÄPHP´úÂëʾÀý£º
if (isset($_GET['close'])) { header('Location: about:blank'); die(); }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÊ×Ïȼì²é$_GETÊý×éÖÐÊÇ·ñ±£´æ¡°close¡±²ÎÊý¡£ÈôÊDZ£´æ£¬ÔòʹÓÃHeaderº¯Êý½«Î»ÖÃÉèÖÃΪ¡°about:blank¡±£¨Ò»¸ö¿ÕȱҳÃ棩¡£È»ºóʹÓÃdie()º¯Êý×èÖ¹¾ç±¾µÄÖ´ÐС£Õ⽫µ¼Ö¿ͻ§¶Ëä¯ÀÀÆ÷¼ÓÔØÖ¸Ïò¡°about:blank¡±µÄÍøÒ³£¬´Ó¶ø¹Ø±Õä¯ÀÀÆ÷»ò´°¿Ú¡£
Äú¿ÉÒÔÔÚControllerÖÐŲÓôËPHPº¯Êý»ò½«Æä·ÅÈëViewÖС£ÀýÈ磬ÔÚViewÖУ¬Äú¿ÉÒÔ½¨ÉèÒ»¸öÁ´½Ó£¬Ö¸ÏòÉÏÊöPHP´úÂ룺
<a href="/close-page?close=1">¹Ø±ÕÒ³Ãæ</a>
µÇ¼ºó¸´ÖÆ
µ±Óû§µ¥»÷Á´½Óʱ£¬½«·¢ËÍÒ»¸öGETÇëÇó£¬ÆäÖаüÀ¨¡°close¡±²ÎÊý¡£ÔÚ´¦Àí´ËÇëÇóʱ£¬ÉÏÊöPHP´úÂ뽫¹Ø±ÕÒ³Ãæ¡£
3.ʹÓÃHTML´úÂëʵÏֹرÕÒ³Ãæ
³ýÁËʹÓÃJavaScriptºÍPHPÖ®Í⣬Äú»¹¿ÉÒÔʹÓÃHTML´úÂëÀ´¹Ø±ÕÒ³Ãæ¡£HTMLÖеıêÇ©¾ßÓÐÒ»¸ötargetÊôÐÔ£¬¿ÉÒÔ½«Ò³ÃæµÄÄ¿µÄÉèÖÃΪ_blank¡£Õ⽫·¿ªÒ»¸öд°¿Ú£¬ÆäÖаüÀ¨Ò»¸ö¿ÕȱҳÃæ¡£ÓÉÓÚд°¿ÚÊÇ¿ÕȱµÄ£¬Òò´ËÄú¿ÉÒÔÒÔΪÄú¸Õ¸Õ¹Ø±ÕÁËÔʼҳÃæ¡£ÒÔÏÂÊÇÒ»¸öʾÀýHTML´úÂ룬¿É×ÊÖúÄúÔÚThinkPHP5ÖÐʹÓÃHTML¹Ø±ÕÒ³Ã棺
<a href="about:blank" target="_blank">¹Ø±ÕÒ³Ãæ</a>
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃǽ¨ÉèÁËÒ»¸öÁ´½Ó£¬ËüµÄÄ¿µÄÉèÖÃΪ_blank£¬²¢½«Î»ÖÃÉèÖÃΪ¡°about:blank¡±¡£µ±Óû§µ¥»÷Á´½Óʱ£¬½«·¿ªÒ»¸öд°¿Ú£¬ÆäÖаüÀ¨Ò»¸ö¿ÕȱҳÃæ¡£Õ⽫¹Ø±ÕÔʼҳÃæ»ò´°¿Ú¡£
×ܽá
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËÔÚThinkPHP5ÖÐʵÏֹرÕÒ³ÃæµÄÈýÖÖ²î±ðÒªÁ죺JavaScript¡¢PHPºÍHTML´úÂë¡£JavaScriptÊÇ×î³£¼ûµÄ½â¾ö¼Æ»®£¬¿ÉÊÇÈôÊÇJavaScript±»½ûÓã¬Ôò´ËÒªÁ콫²»Æð×÷Óá£ÓÉÓÚPHPºÍHTML´úÂëÔÚºǫִ́ÐУ¬Òò´ËËüÃÇ¿ÉÒÔʼÖÕÕý³£ÊÂÇ飬×ÝÈ»JavaScript±»½ûÓá£ÎÞÂÛÄúÑ¡ÔñÄÄÖÖÒªÁ죬¶¼Ó¦¸Ã×Ðϸ˼Á¿ÄúµÄWebÓ¦ÓóÌÐòµÄÐèÇ󣬲¢Ñ¡Ôñ×îÊʺÏÄúµÄ½â¾ö¼Æ»®¡£
ÒÔÉϾÍÊÇthinkphp5¹Ø±ÕÒ³ÃæµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡