thinkphpÔõôʵÏÖÌøתҳÃæ
Ò»¡¢Ê¹ÓÃredirectº¯ÊýÌøתҳÃæ
ÔÚthinkphpÖУ¬Ìøתµ½ÆäËûÒ³Ãæ¿ÉÒÔʹÓÃredirectº¯Êý¡£¸Ãº¯ÊýµÄÓ÷¨ÈçÏ£º
public function redirect($url, $params = [], $code = 302, $withPrefix = false)
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬$urlÌåÏÖÒªÌøתµÄÒ³Ãæ·¾¶£¬$paramsÌåÏÖÌøתʱÐèҪת´ïµÄ²ÎÊý£¬$codeÌåÏÖÌøתµÄHTTP״̬Â룬$withPrefixÌåÏÖÊÇ·ñ´øÉÏÓòÃûǰ׺¡£ÏÂÃæÊÇһЩʹÓøú¯ÊýµÄʾÀý£º
1.Ìøתµ½ÆäËû¿ØÖÆÆ÷µÄÒªÁì
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
// Ìøתµ½Home¿ØÖÆÆ÷µÄindexÒªÁì return $this->redirect('home/index');
µÇ¼ºó¸´ÖÆ
2.Ìøתµ½ÍⲿURL
return $this->redirect('http://www.example.com');
µÇ¼ºó¸´ÖÆ
3.´ø²ÎÊýÌøת
// Ìøתµ½Home¿ØÖÆÆ÷µÄdetailÒªÁ죬²¢×ª´ïid²ÎÊý return $this->redirect('home/detail', ['id' => 1]);
µÇ¼ºó¸´ÖÆ
¶þ¡¢Ê¹ÓÃurlº¯ÊýÌìÉúÌøת·¾¶
³ýÁËʹÓÃredirectº¯ÊýÌøתҳÃæÍ⣬»¹¿ÉÒÔʹÓÃurlº¯ÊýÌìÉúÌøת·¾¶£¬È»ºóʹÓÃredirectº¯Êý¾ÙÐÐÌøת¡£urlº¯ÊýµÄÓ÷¨ÈçÏ£º
public function url($url = '', $vars = '', $suffix = true, $domain = false)
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬$urlÌåÏÖÒªÌìÉúµÄURLµØµã£¬$varsÌåÏÖҪת´ïµÄ²ÎÊý£¬$suffixÌåÏÖÊÇ·ñÆôÓÃURLºó׺£¬$domainÌåÏÖÊÇ·ñ´øÉÏÓòÃûǰ׺¡£
ÏÂÃæÊÇÒ»¸öʹÓÃurlº¯ÊýÌìÉúÌøת·¾¶µÄʾÀý£º
// ÌìÉúHome¿ØÖÆÆ÷µÄindexÒªÁìµÄURL $url = $this->url('home/index'); return $this->redirect($url);
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇthinkphpÔõôʵÏÖÌøתҳÃæµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡