thinkphp·Óɲ»×ª»»ÎÊÌâÔõÑù½â¾ö
Ò»¡¢ÎÊÌâÐÎò
ÔÚÎÒÃÇʹÓÃThinkPHP¾ÙÐпª·¢Ê±£¬ÓÐʱ»áÓöµ½ÕâÑùµÄÇéÐΣºµ±ÎÒÃǾÙÐÐһЩ·ÓɲÙ×÷ʱ£¬Ò³Ã沢δÌøתÖÁÎÒÃÇËùÆÚÍûµÄ½çÃæ¡£
ÀýÈ磬ÎÒÃÇÏ£Íûͨ¹ýURL¡°www.example.com/home/do¡±À´»á¼û¡°HomeController.php¡±Öеġ°do¡±ÒªÁ죬µ«ÎÒÃÇÏÖʵÉÏÈ´ÎÞ·¨»á¼ûµ½´ËÒªÁ졣ͬʱ£¬ÎÒÃÇ·¢Ã÷²¢Ã»Óб¨´íÐÅÏ¢·ºÆð£¬Õâ¾ÍÈÃÎÒÃÇÎÞ´ÓÏÂÊÖ¡£
¶þ¡¢Ôµ¹ÊÔÓÉÆÊÎö
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚThinkPHPÖУ¬Â·ÓÉÊÇͨ¹ýURLºó׺¾ÙÐÐÆ¥ÅäµÄ¡£ÈôÊÇÔÚÎÒÃǵÄURLÖÐûÓÐʹÓÃÈκκó׺£¬ÄÇôThinkPHP½«ÒÔΪÎÒÃÇÒª»á¼ûµÄÒªÁìÊÇ¿ØÖÆÆ÷ÖеÄĬÈÏÒªÁ죨ĬÈÏÒªÁìÃûÒ»Ñùƽ³£Îª¡°index¡±£©¡£
ÀýÈ磬ÎÒÃÇʹÓÃURL¡°www.example.com/home/index¡±Ê±£¬¾Í»áĬÈÏ»á¼û¡°HomeController.php¡±Öеġ°index¡±ÒªÁì¡£
¶øµ±ÎÒÃÇʹÓÃURL¡°www.example.com/home/do¡±Ê±£¬ÓÉÓÚûÓÐʹÓÃÈκκó׺£¬ThinkPHP¾Í»áÒÔΪÎÒÃÇÒª»á¼ûµÄÊÇ¡°index¡±ÒªÁ죬ͬʱÓÉÓÚ¡°do¡±ÒªÁì²¢²»±£´æÓÚ¿ØÖÆÆ÷ÖУ¬ÒÔÊǾͻᵼÖÂÒ³Ãæ»á¼ûʧ°Ü¡£
Èý¡¢½â¾öÒªÁì
1.ʹÓá°/¡±ºó׺
ÈôÊÇÔÚURLĩβÌí¼Óб¸Ü¡°/¡±£¬¾Í¿ÉÒÔ×èÖ¹·ºÆð·Óɲ»Æ¥ÅäµÄÇéÐΡ£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓÃURL¡°www.example.com/home/do/¡±À´»á¼û¡°HomeController.php¡±Öеġ°do¡±ÒªÁì¡£
ͬʱ£¬ÎÒÃÇÔÚʹÓÃThinkPHP¾ÙÐпª·¢Ê±£¬ÍƼöÔÚÉèÖÃÎļþconfig.phpÖн«URLºó׺ÉèÖÃΪ¡°/¡±£¬ÕâÑù¿ÉÒÔ×èÖ¹·ºÆð·Óɲ»×ª»»µÄÎÊÌâ¡£
2.Ð޸ķÓɹæÔò
ÎÒÃÇÒ²¿ÉÒÔͨ¹ýÐ޸ķÓɹæÔòÀ´½â¾öÎÊÌâ¡£
Ê×ÏÈ£¬ÔÚÎÒÃǵÄ·ÓÉÉèÖÃÎļþÖУ¨Ò»Ñùƽ³£Îªroute.php£©£¬ÎÒÃÇ¿ÉÒÔ½«Â·ÓɹæÔò½ç˵Ϊ£º
return [ 'home/do/[:id]' => 'home/[:action]', ];
µÇ¼ºó¸´ÖÆ
ÕâÑù£¬ÎÒÃǾͿÉÒÔͨ¹ýURL¡°www.example.com/home/do/1¡±À´»á¼û¡°HomeController.php¡±Öеġ°do¡±ÒªÁ죬²¢ÔÚURLÖÐת´ïÒ»¸öid²ÎÊý¡£
ÒÔÉϾÍÊÇthinkphp·Óɲ»×ª»»ÎÊÌâÔõÑù½â¾öµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡