×ðÁú¿­Ê±¹ÙÍøµÇ¼

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µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ