laravelÌøתҳÃæ´«id
ÔÚlaravelÖУ¬ÌøתҳÃ沢ת´ï²ÎÊýÊǷǾ³£¼ûµÄÐèÇó¡£ÆäÖУ¬°Ñid×÷Ϊ²ÎÊýת´ï¸øÏÂÒ»¸öÒ³ÃæÊÇÊ®·Ö³£¼ûµÄÐèÇó¡£±¾ÎĽ«½â˵ÔõÑùÔÚlaravelÖÐʵÏÖÌøתҳÃ沢ת´ïid²ÎÊýµÄÒªÁì¡£
µÚÒ»ÖÖÒªÁ죺ʹÓÃURL´«²Î
ʹÓÃURL´«²ÎÊÇ×î³£ÓõĴ«²ÎÒªÁìÖ®Ò»¡£Ëü¿ÉÒÔÈÃÎÒÃÇÔÚURLÖÐÌí¼ÓÐèҪת´ïµÄ²ÎÊý£¬È»ºóÔÚÏÂÒ»¸öÒ³ÃæÖÐͨ¹ý»ñÈ¡URL²ÎÊýÀ´Ê¹Óá£ÏÂÃæÊÇÏêϸʵÏÖ°ì·¨£º
Ê×ÏÈ£¬ÔÚ¿ØÖÆÆ÷ÖлñÈ¡²ÎÊý²¢Æ´½ÓURL£º
public function jump(Request $request) { $id = $request->input('id'); $url = '/detail?id=' . $id; return redirect($url); }
µÇ¼ºó¸´ÖÆ
ÉÏÊö¿ØÖÆÆ÷ÒªÁìÖУ¬ÎÒÃÇͨ¹ý$request->input(‘id’)»ñȡת´ï¹ýÀ´µÄID£¬²¢½«ÆäÆ´½ÓÔÚURLÖС£È»ºóʹÓÃredirect($url)ÒªÁì¾ÙÐÐÌøת¡£ÏÂÃæÎÒÃÇÀ´¿´¿´ÔõÑùÔÚÏÂÒ»¸öÒ³ÃæÖлñÈ¡ID²ÎÊý¡£
public function detail(Request $request) { $id = $request->input('id'); // ... }
µÇ¼ºó¸´ÖÆ
ÔÚÏÂÒ»¸ö´¦ÀíÒ³ÃæÖУ¬ÎÒÃÇͬÑùʹÓÃ$request->input(‘id’)ÒªÁì»ñÈ¡URLÖÐת´ï¹ýÀ´µÄID²ÎÊý£¬È»ºó¾Í¿ÉÒÔʹÓÃÕâ¸ö²ÎÊý¾ÙÐÐÏà¹ØµÄ²Ù×÷ÁË¡£
µÚ¶þÖÖÒªÁ죺ʹÓÃSession´«²Î
ÁíÒ»ÖÖ³£¼ûµÄ´«²ÎÒªÁìÊÇʹÓÃSession¡£ÕâÖÖÒªÁì¿ÉÒÔÔÚ²»Ì»Â¶²ÎÊýÐÅÏ¢µÄÇéÐÎÏÂת´ïÊý¾Ý¡£
Ê×ÏÈ£¬ÔÚ¿ØÖÆÆ÷Öн«²ÎÊý´æ´¢µ½SessionÖУº
public function jump(Request $request) { $id = $request->input('id'); $request->session()->put('id', $id); return redirect('/detail'); }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇͨ¹ý$request->session()->put(‘id’, $id)ÒªÁ콫ת´ï¹ýÀ´µÄID´æ´¢µ½SessionÖУ¬È»ºóʹÓÃredirect(‘/detail’)ÒªÁì¾ÙÐÐÌøת¡£
½ÓÏÂÀ´£¬ÔÚÏÂÒ»¸öÒ³ÃæÖÐͨ¹ýSession»ñÈ¡ID²ÎÊý£º
public function detail(Request $request) { $id = $request->session()->get('id'); // ... }
µÇ¼ºó¸´ÖÆ
ÔÚÏÂÒ»¸ö´¦ÀíÒ³ÃæÖУ¬ÎÒÃÇͬÑùʹÓÃ$request->session()->get(‘id’)ÒªÁì»ñÈ¡SessionÖд洢µÄID²ÎÊý£¬È»ºó¾Í¿ÉÒÔʹÓÃÕâ¸ö²ÎÊý¾ÙÐÐÏà¹ØµÄ²Ù×÷ÁË¡£
×ܽá
ÒÔÉϾÍÊÇÁ½ÖÖ³£ÓõÄÔÚLaravelÖÐÌøתҳÃ沢ת´ïID²ÎÊýµÄÒªÁì¡£ÎÞÂÛÊÇʹÓÃURL´«²ÎÕÕ¾ÉʹÓÃSession´«²Î£¬¶¼¿ÉÒÔ¿ìËÙ¼òÆÓµØʵÏÖÕâÒ»ÐèÇó¡£ÔÚʹÓÃÕâЩҪÁìµÄʱ¼ä£¬ÎñÐëҪעÖزÎÊýµÄÇå¾²ÐÔ£¬×èÖ¹·ºÆð²ÎÊý±»¶ñÒâ¸Ä¶¯µÄÇéÐΡ£
ÒÔÉϾÍÊÇlaravelÌøתҳÃæ´«idµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡