×ðÁú¿­Ê±

thinkphp5Ôõô´«id

thinkphp 5 ÊÇÒ»¸öÊ¢ÐÐµÄ php ¿ò¼Ü£¬ËüÌṩÁËÎÞаµÄ±à³Ì·½·¨ºÍÓÅÒìµÄÐÔÄÜÌåÏÖ¡£ÔÚʹÓøÿò¼Ü¿ª·¢ÏîĿʱ£¬¾­³£ÐèÒª»ñÈ¡²¢×ª´ï id ²ÎÊý¡£±¾ÎĽ«ÏÈÈÝÔÚ thinkphp 5 ÖÐÔõÑùת´ï id¡£

ÔÚ ThinkPHP 5 ÖУ¬»ñÈ¡ ID µÄ·½·¨ÓÐÐí¶àÖÖ¡£Ò»Ñùƽ³£ÇéÐÎÏ£¬ÎÒÃÇ¿ÉÒÔÔÚ·ÓÉÉèÖÃÎļþÖÐʹÓÃռλ·ûÀ´»ñÈ¡ ID¡£ÀýÈ磬½ç˵һ¸ö·ÓÉÈçÏ£º

Route::get('user/:id','user/read');

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö·ÓÉÖУ¬:id ¾ÍÊÇռλ·û£¬ÌåÏÖ»ñÈ¡ÃûΪ id µÄ²ÎÊý¡£´Ëʱ£¬ÎÒÃÇ¿ÉÒÔÔÚ user Ä £¿éµÄ read ÒªÁìÖÐʹÓà request() º¯Êý»ñÈ¡ ID ²ÎÊý£¬´úÂëÈçÏ£º

public function read($id)
{
    echo 'User ID: '.$id;
}

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂëÖУ¬$id ²ÎÊý¾ÍÊÇͨ¹ýռλ·û :id ת´ï¹ýÀ´µÄ ID Öµ¡£ÎÒÃÇ¿ÉÒÔÔÚ read ÒªÁìÖжԸÃÖµ¾ÙÐвÙ×÷»òÕßÊä³ö¡£

³ýÁËÔÚ·ÓÉÖÐʹÓÃռλ·û»ñÈ¡ ID ÖµÒÔÍ⣬»¹¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐͨ¹ý request() º¯ÊýµÄ²ÎÊý»ñÈ¡ ID Öµ¡£ÀýÈ磬¼ÙÉè User Ä £¿éÏÂÓÐÒ»¸ö InformationController ¿ØÖÆÆ÷£¬ÇÒÓÐÒ»¸ö edit ÒªÁ죺

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

public function edit(Request $request)
{
    $id = $request->param('id');
    echo 'Information ID: '.$id;
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃÁË $request ²ÎÊýÀ´»ñÈ¡Ä¿½ñÇëÇóµÄÐÅÏ¢£¬²¢Í¨¹ý param() ÒªÁì»ñÈ¡ÃûΪ id µÄ²ÎÊýÖµ¡£´Ëʱת´ïµÄ²ÎÊýÐèҪͨ¹ý URL µÄÅÌÎÊ×Ö·û´®ÐÎʽ¾ÙÐÐת´ï£¬ÀýÈ磺

http://example.com/index.php/user/information/edit?id=1

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö URL ÖУ¬id ²ÎÊýµÄֵΪ 1£¬¼´×ª´ï¸ø edit ÒªÁìµÄ ID Öµ¡£

³ýÁËʹÓ÷ÓÉÖеÄռλ·ûºÍÅÌÎÊ×Ö·û´®µÄ·½·¨×ª´ï ID ÖµÒÔÍ⣬»¹¿ÉÒÔʹÓÃÔ½·¢¸ß¼¶µÄ·½·¨ÔÚ´úÂëÖлñÈ¡ ID Öµ¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓ÷ÓÉÖеÄĬÈÏÖµ»ñÈ¡ ID Öµ£¬ÈçÏ£º

Route::get('user/[:id]','user/read', ['id' => '\d+']);

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖУ¬Ê¹ÓÃÀ¨ºÅ½« :id ¸ÄΪ [:id]£¬²¢Í¨¹ý [‘id’ => ‘\d+’] Ö¸¶¨ÁË ID µÄĬÈÏֵΪÊý×Ö¡£´Ëʱ£¬ÈôÊÇ URL ÖÐδָ¶¨ ID Öµ£¬ÔòĬÈÏʹÓøÃĬÈÏÖµ¡£ÀýÈ磺

http://example.com/index.php/user/read

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö URL ÖУ¬Î´×ª´ï ID Öµ£¬¿ÉÊÇÓÉÓÚʹÓÃÁËĬÈÏÖµ£¬Òò´Ë $id ±äÁ¿µÄÖµ½«Îª 0¡£ÎÒÃÇÒ²¿ÉÒÔÔÚ¿ØÖÆÆ÷»òÕßÄ£×ÓÖÐʹÓÃĬÈÏÖµ·½·¨»ñÈ¡ ID Öµ¡£

×ܽáÀ´Ëµ£¬»ñÈ¡ºÍת´ï ID ÖµÔÚ ThinkPHP 5 ÖÐÓжàÖÖ·½·¨¡£ÎÒÃÇ¿ÉÒÔƾ֤ÐèҪѡÔñ²î±ðµÄ·½·¨»ñÈ¡ºÍת´ï ID Öµ£¬²¢ÔÚ´úÂëÖжÔÆä¾ÙÐд¦Öóͷ£ºÍÔËÓá£ÔÚÏÖʵ¿ª·¢ÖУ¬ÐèҪƾ֤ÏêϸÇéÐÎÑ¡Ôñ²î±ðµÄ·½·¨£¬ÒÔʵÏÖÔ½·¢ÎÞаµÄ±à³ÌºÍÓ¦Óá£

ÒÔÉϾÍÊÇthinkphp5Ôõô´«idµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

13452372176

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

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

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