ÔõÑùÔÚthinkphpÖÐʵÏÖÌøתµ½ÁíÒ»¸öÒªÁì
ÔÚʹÓÃphp¿ò¼Üthinkphp¾ÙÐпª·¢Ê±£¬ÓÐʱ¼äÎÒÃÇÐèÒªÔÚÒ»¸öÒªÁìÖÐÌøתµ½ÁíÒ»¸öÒªÁì¡£ÕâÖÖÇéÐÎÔÚÏÖʵ¿ª·¢ÖзǾ³£¼û¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphpÖÐʵÏÖÌøתµ½ÁíÒ»¸öÒªÁì¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏàʶthinkphpÖеÄ·ÓÉ¿´·¨¡£thinkphp½ÓÄÉ·ÓÉ»úÖÆÀ´´¦ÀíÇëÇó£¬Â·ÓÉ»úÖÆÈÏÕ潫Óû§ÇëÇóÓ³Éäµ½¶ÔÓ¦µÄ¿ØÖÆÆ÷ÒªÁì¡£
ÔÚthinkphpÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýURLµØµãÀ´»á¼û¿ØÖÆÆ÷µÄÒªÁ죬ͨ³£µÄURLµØµãÃûÌÃΪ£º
http:////
µÇ¼ºó¸´ÖÆ
ÀýÈ磬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂURLµØµã»á¼û¿ØÖÆÆ÷IndexµÄÒªÁìhello£º
http://example.com/index/hello
µÇ¼ºó¸´ÖÆ
ÔÚthinkphpÖУ¬ÒªÌøתµ½ÁíÒ»¸öÒªÁ죬ÎÒÃÇ¿ÉÒÔʹÓÃredirectº¯Êý¡£Õâ¸öº¯ÊýµÄ×÷ÓÃÊǽ«ÇëÇóÖض¨Ïòµ½Ö¸¶¨µÄURLµØµã»ò·Óɵص㡣
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÕâÀïÐèҪעÖصÄÊÇ£¬ÈôÊÇÎÒÃÇÒªÌøתµ½Ä¿½ñ¿ØÖÆÆ÷µÄÁíÒ»¸öÒªÁ죬ÎÒÃÇ¿ÉÒÔÖ±½ÓʹÓÿØÖÆÆ÷ÒªÁìµÄÃû³Æ×÷Ϊ·Óɵص㡣ÀýÈ磬¿ØÖÆÆ÷IndexÖÐÓÐÒ»¸öÒªÁìtest£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ´úÂ뽫ÇëÇóÖض¨Ïòµ½¸ÃÒªÁ죺
$this->redirect('test');
µÇ¼ºó¸´ÖÆ
µ±ÎÒÃÇʹÓÃ$this->redirect(‘test’)ʱ£¬thinkphp»á×Ô¶¯½«test×÷Ϊ·Óɵص㣬ȻºóÖ´ÐпØÖÆÆ÷IndexµÄÒªÁìtest¡£
ÈôÊÇÎÒÃÇÒªÌøתµ½ÆäËû¿ØÖÆÆ÷µÄÒªÁ죬ÎÒÃÇÐèҪʹÓÃÍêÕûµÄ·Óɵص㡣ÀýÈ磬ҪÌøתµ½¿ØÖÆÆ÷UserµÄÒªÁìlogin£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂ룺
$this->redirect('user/login');
µÇ¼ºó¸´ÖÆ
ÕâÀïµÄuserÊÇ¿ØÖÆÆ÷Ãû£¬loginÊÇÒªÁìÃû¡£thinkphp»áƾ֤·ÓɵصãÖ´ÐжÔÓ¦µÄ¿ØÖÆÆ÷µÄÒªÁì¡£
³ýÁËÖ¸¶¨ÍêÕûµÄ·Óɵص㣬ÎÒÃÇ»¹¿ÉÒÔʹÓÃÊý×éÀ´½ç˵·Óɵص㡣ÀýÈ磬ҪÌøתµ½¿ØÖÆÆ÷UserµÄÒªÁìlist£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂ룺
$this->redirect(['user/list']);
µÇ¼ºó¸´ÖÆ
ʹÓÃÊý×éµÄ·½·¨¿ÉÒÔÔ½·¢ÎÞаµØ½ç˵·Óɵص㣬¿ÉÒÔת´ï¸ü¶àµÄ²ÎÊýÐÅÏ¢¡£
ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇÒ²ºÜÈÝÒ×·ºÆðÐèҪת´ï²ÎÊýµ½ÌøתµÄÒªÁìÖеÄÇéÐΡ£ÔÚthinkphpÖУ¬ÎÒÃÇ¿ÉÒÔʹÓñäÁ¿À´×ª´ï²ÎÊý¡£ÀýÈ磬ÎÒÃÇÒªÌøתµ½¿ØÖÆÆ÷UserµÄÒªÁìdetail£¬²¢ÇÒ´øÉϲÎÊýid=1£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂ룺
$id = 1; $this->redirect('user/detail', ['id' => $id]);
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊö´úÂëÖУ¬ÎÒÃÇÊ×ÏȽç˵ÁËÒ»¸ö$id±äÁ¿£¬¸Ã±äÁ¿µÄֵΪ1¡£È»ºóÎÒÃÇʹÓÃ$this->redirect(‘user/detail’, [‘id’ => $id])½«ÇëÇóÖض¨Ïòµ½¿ØÖÆÆ÷UserµÄÒªÁìdetail£¬²¢ÇÒת´ïÁËÒ»¸ö²ÎÊýid£¬ÆäֵΪ±äÁ¿$idµÄÖµ¡£
ÔÚÌøתʱ£¬ÎÒÃÇ»¹¿ÉÒÔÖ¸¶¨ÌøתµÄ·½·¨¡£thinkphpÖ§³ÖÒÔÏÂÌøת·½·¨£º
Ò³ÃæÌøת£¨Ä¬ÈÏ£©£ºÊ¹ÓÃ301»ò302״̬Â룬ä¯ÀÀÆ÷»á×Ô¶¯Ìøתµ½Ö¸¶¨µÄURLµØµã¡£
AJAXÌøת£ºÊ¹ÓÃJSONÃûÌ÷µ»ØÌøתµØµã£¬ÓÉÇ°¶Ë×ÔÐÐÌøת¡£
Öض¨Ïò£ºÊ¹ÓÃHTTP״̬Âë302ÔÚЧÀÍÆ÷¶Ë½«ÇëÇóÖض¨Ïòµ½Ö¸¶¨µÄURLµØµã¡£
ÈôÊDz»Ö¸¶¨Ìøת·½·¨£¬thinkphp½«Ä¬ÈÏʹÓÃÒ³ÃæÌøת¡£
×ܽ᣺
ÔÚthinkphpÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýredirectº¯Êý¾ÙÐÐÌøתµ½ÁíÒ»¸öÒªÁì¡£ÎÒÃÇ¿ÉÒÔʹÓÿØÖÆÆ÷ÒªÁìµÄÃû³Æ×÷Ϊ·Óɵص㣬Ҳ¿ÉÒÔʹÓÃÍêÕûµÄ·Óɵص㡣ÔÚÌøתʱ£¬ÎÒÃÇ»¹¿ÉÒÔת´ï²ÎÊý£¬²¢ÇÒ¿ÉÒÔÖ¸¶¨Ìøת·½·¨¡£×£¸÷ÈËÔÚthinkphp¿ª·¢ÖÐÄܹ»Ë³ËìʵÏÖÌøתµ½ÁíÒ»¸öÒªÁì¡£
ÒÔÉϾÍÊÇÔõÑùÔÚthinkphpÖÐʵÏÖÌøתµ½ÁíÒ»¸öÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡