尊龙凯时人生就是搏

ÔõÑùÔÚThinkPHP6ÖÐʹÓÃÓѺõÄURLµØµã£¿

Ëæ×Å»¥ÁªÍøµÄÉú³¤ £¬Ô½À´Ô½¶àµÄÍøÕ¾ÐèҪ˼Á¿ÓÅ»¯Óû§ÌåÑé £¬ÆäÖÐÒ»¸ö·½Ãæ¾ÍÊÇÓѺõÄurlµØµã¡£thinkphp ÊÇÒ»¿îÓÅÒìµÄ php ¿ò¼Ü £¬¹ØÓÚ url µØµãµÄ´¦ÀíÒ²ÌṩÁ˱ã½ÝµÄ½â¾ö¼Æ»®¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ thinkphp6 ÖÐʹÓÃÓÑºÃµÄ url µØµã¡£

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÏàʶÏ ThinkPHP6 ÖйØÓÚ·ÓɵÄÏà¹Ø¿´·¨¡£Â·ÓÉÊÇÖ¸½« URL ÇëÇóת·¢µ½Ö¸¶¨µÄ¿ØÖÆÆ÷ºÍÒªÁì £¬ÊµÏÖ²î±ðµÄÓªÒµÂß¼­¡£ThinkPHP6 ¿ÉÒÔͨ¹ý¿ØÖÆÆ÷×¢½âµÄ·½·¨½ç˵·ÓÉÐÅÏ¢ £¬ÕâÖÖ·½·¨ÔÚά»¤Àú³ÌÖÐÔ½·¢Àû±ã¡£

¹ØÓÚ URL µØµã £¬ÎÒÃdz£¼ûµÄÓÐÒÔÏÂÁ½ÖÖÐÎʽ£º

1.¹Å°åµÄURLµØµãÈ磺http://www.example.com/index.php/Controller/Action/id/1

2.α¾²Ì¬URLµØµãÈ磺http://www.example.com/Controller/Action/id/1

ÔÚµÚÒ»ÖֹŰåµÄ URL µØµãÖÐ £¬ÎÒÃÇÐèÒªÔÚ URL µØµãÖÐÊÖ¶¯Ìí¼Ó¿ØÖÆÆ÷ºÍÒªÁìÃû²¢ÒÔ id ²ÎÊýµÄ·½·¨×ª´ïÊý¾Ý £¬ÉÔÓÐʧÉ÷¿ÉÄܻᵼÖ´úÂëÔÓÂÒÇÒÄÑÒÔά»¤¡£ÔÚµÚ¶þÖÖα¾²Ì¬ URL µØµãÖÐ £¬ÎÒÃÇ¿ÉÒÔ½« ID µÈ²ÎÊýת»¯Îª¿É¶ÁÐÔ¸ßÇÒÒ×ÓÚά»¤µÄ URL µØµã¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

½ÓÏÂÀ´ £¬ÎÒÃÇÏÈÈÝÔõÑùʹÓ÷ÓÉÀ´ÊµÏÖα¾²Ì¬ URL µØµã¡£

1.ÉèÖ÷ÓÉ

config/route.php ÎļþÊÇ·ÓÉÎļþ £¬ÎÒÃÇ¿ÉÒÔÔÚ´ËÎļþÖÐÉèÖ÷ÓÉÐÅÏ¢¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÉèÖÃʾÀý£º

use thinkacadeRoute;

Route::rule('article/:id', 'index/article/read')
        ->pattern(['id' => 'd+']);

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬ÎÒÃÇͨ¹ý Route::rule() ÒªÁìÉèÖÃÁËÒ»¸öÃûΪ article/:id µÄ URL µØµã £¬ÆäÖÐ :id ²¿·ÖÊÇ URL ²ÎÊý £¬ËüÌåÏÖÐèҪת´ïµÄÊý¾Ý¡£Â·ÓɵÄÏÖʵ²Ù×÷ÔòÊǽ«´Ë URL µØµãת·¢µ½Ò»¸öÃûΪ index/article/read µÄ¿ØÖÆÆ÷ºÍÒªÁìÖС£

ͬʱ £¬ÎÒÃÇ¿ÉÒÔʹÓà ->pattern() ÒªÁìÀ´ÏÞÖƲÎÊýÃûÌá£ÔÚÉÏÊöÀý×ÓÖÐ £¬ÎÒÃÇÏÞÖÆÁË :id ²ÎÊýµÄÖµÖ»ÄÜÊÇÊý×Ö¡£

2.½ç˵¿ØÖÆÆ÷

½ç˵ºÃ·ÓÉÐÅÏ¢ºó £¬ÎÒÃÇÐèÒªÔÚ¿ØÖÆÆ÷ÖÐʵÏÖ¶ÔÓ¦µÄÒªÁì £¬À´´¦ÀíÇëÇó²¢·µ»ØÄÚÈÝ¡£ÔÚ¿ØÖÆÆ÷Îļþ£¨Î»ÓÚ app/controller Ŀ¼Ï£©ÖÐ £¬ÎÒÃÇ¿ÉÒÔ½ç˵һ¸öÃûΪ article µÄ¿ØÖÆÆ÷ÀàºÍÒ»¸öÃûΪ read µÄÒªÁì¡£

namespace appcontroller;

use thinkRequest;

class Article
{
    public function read($id)
    {
        return 'ÕýÔÚÔĶÁÎÄÕ ' . $id;
    }
}

µÇ¼ºó¸´ÖÆ

3.»á¼ûURL

ÏÖÔÚ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýµØµãÀ¸»á¼ûÎÒÃǵÄÍøÕ¾ÁË £¬ÀýÈçÊäÈëÒÔÏ URL µØµã£ºhttp://www.example.com/article/1  £¬¶ÔÓ¦¿ØÖÆÆ÷ÖÐµÄ /:id ²ÎÊýֵΪ 1 £¬´Ó¶ø½øÈë³ÌÐò´¦ÀíÁ÷³Ì¡£Íê³É·ÓÉת·¢ºó £¬ÎÒÃǽ«ÇëÇóת´ï¸ø Article ¿ØÖÆÆ÷µÄ read ÒªÁìÀ´´¦ÀíÇëÇó¡£ÔÚÍê³É´¦Àíºó £¬ÎÒÃǽ«·µ»ØÄÚÈÝÏÔʾÔÚÇ°¶ËÒ³ÃæÖÐ £¬ÊµÏÖÁËÓÑºÃµÄ URL µØµã¡£

±¾ÎÄÏÈÈÝÁËÔÚThinkPHP6ÖÐʵÏÖÓѺÃURLµØµãµÄÏêϸҪÁ졣ʹÓ÷ÓÉ¿ÉÒÔÓÐÓõØ×èÖ¹·±ËöµÄ URL µØµãÊäÈëºÍ´ó×ڵIJÎÊýµÄת´ï £¬ÈôúÂëÔ½·¢Ò×ÓÚά»¤ £¬Ìá¸ßÁËÓû§ÌåÑé¡£

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖÐʹÓÃÓѺõÄURLµØµã£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ