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

thinkphp3.2ÔõôʹÓÃÁ¬Ã¦Ìøת¹¦Ð§

ThinkPHP¿ò¼ÜÖУ¬Ìøת¹¦Ð§¿ÉÒÔʹÓÃredirectÒªÁìÀ´ÊµÏÖ¡£ÓÉÓÚ¸ÃÒªÁì½ç˵ÔÚ¿ØÖÆÆ÷»ùÀàÖУ¬ÒÔÊÇ¿ØÖÆÆ÷¿ÉÒÔÖ±½ÓŲÓÃËüÀ´ÊµÏÖÁ¬Ã¦ÌøתµÄ¹¦Ð§¡£redirectÒªÁì½ÓÊÜÁ½¸ö²ÎÊý£º$urlºÍ$params¡£

ÆäÖУ¬$urlÊÇÖض¨ÏòµÄURLµØµã¡£¸Ã²ÎÊý¿ÉÒÔÊǼòÆÓµÄ×Ö·û´®£¬Ò²¿ÉÒÔÊÇÊý×é»òÒÔ#¿ªÍ·µÄêµãÖµ¡£ÌÈʹ$Url²ÎÊýÊÇÒ»¸öÊý×飬ÆäÖпÉÒÔ°üÀ¨Â·ÓɹæÔòÓÖÃû¡¢¿ØÖÆÆ÷Ãû³Æ¡¢²Ù×÷Ãû³ÆÒÔ¼°²ÎÊýÁбí¡£¼´Êý×é¿ÉÒÔͨ¹ýÖ¸¶¨²î±ðµÄÔªËØ£¬µÖ´ï²î±ðµÄÌøתЧ¹û¡£

$paramsÊÇÒ»¸ö¿ÉÑ¡²ÎÊý£¬¿ÉÓÃÓÚÖ¸¶¨¸½¼Óµ½GETÇëÇóµÄ²ÎÊý¡£¸Ã²ÎÊýÖ»ÓÐÔÚURLÖÐûÓÐÅÌÎÊ×Ö·û´®£¨¼´¡°£¿¡±£©Ê±²ÅÓÐÓá£ÈôÊÇURLÒѾ­°üÀ¨ÅÌÎÊ×Ö·û´®£¬ÄÇô$params½«±»ºöÂÔ¡£

ÏÂÃæÊÇÒ»¸öʹÓÃredirectÒªÁìµÄʾÀý£º

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

class IndexController extends Controller
{
    public function index()
    {
        // Ö±½ÓÌøתµ½°Ù¶ÈÊ×Ò³
        $this->redirect('http://www.www.linesum.net');
    }

    public function test()
    {
        // Ìøתµ½Ä¿½ñ¿ØÖÆÆ÷Index²Ù×÷ÖÐ
        $this->redirect('Index/index');

        // Ìøתµ½Home¿ØÖÆÆ÷ÖеÄIndex²Ù×÷
        $this->redirect('Home/Index/index');

        // Ìøת²¢×ª´ï$name²ÎÊý
        $this->redirect('Index/index', array('name' => 'ThinkPHP'));

        // Ìøת²¢×ª´ï¶à¸ö²ÎÊý
        $this->redirect('Index/index', array('name' => 'ThinkPHP', 'id' => 100));
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëʾÀýÖУ¬Ê¹ÓÃÁËredirectÒªÁìʵÏÖÁ˶àÖÖÌøת¹¦Ð§¡£Èç $this->redirect(‘http://www.www.linesum.net’); ¾ÍÊÇÖ±½ÓÌøתµ½°Ù¶ÈÊ×Ò³µÄ²Ù×÷¡£ $this->redirect(‘Index/index’); ÔòÊÇÌøתµ½Ä¿½ñ¿ØÖÆÆ÷Index²Ù×÷ÖС£ $this->redirect(‘Home/Index/index’); Ö¸µÄÊÇÌøתµ½Home¿ØÖÆÆ÷ÖеÄIndex²Ù×÷¡£ $this->redirect(‘Index/index’, array(‘name’ => ‘ThinkPHP’)); ÔòÊÇÌøת²¢×ª´ï$name²ÎÊý¡£ $this->redirect(‘Index/index’, array(‘name’ => ‘ThinkPHP’, ‘id’ => 100)); ÊÇÌøת²¢×ª´ï¶à¸ö²ÎÊý¡£

³ýÁ˽«ÍøÒ³Öض¨Ïòµ½Ö¸¶¨URL£¬redirectÒªÁìÒ²¿ÉÒÔ½«ÆäÖض¨Ïòµ½Â·ÓɹæÔòµÄÓÖÃû¡£ÔÚÕâÖÖÇéÐÎÏ£¬$url²ÎÊýÓ¦¸ÃÊÇÒ»¸ö·ÓÉÓÖÃû£¬¶ø²»ÊÇURLµØµã¡£ÀýÈ磬¼ÙÉèÎÒÃÇÓÐÒÔÏ·ÓɹæÔò£º

// ·ÓɹæÔò½ç˵
'link/:id' => 'Links/link',

µÇ¼ºó¸´ÖÆ

ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐʹÓ÷ÓɹæÔòÓÖÃû¡°link¡±Å²ÓÃredirectÒªÁ죬´Ó¶øÌøתµ½Á´½ÓÒ³Ãæ¡£ÀýÈ磺

class LinksController extends Controller
{
    public function link()
    {
        $id = I('get.id');
        $link = M('Links')->where(array('id'=>$id))->find();

        // ÑéÖ¤Á´½ÓÊÇ·ñ±£´æ
        if ($link) {
            // Ìøתµ½Öؽç˵µÄ·ÓɹæÔòÉÏ
            $this->redirect('link/'.$id);
        } else {
            $this->error('Á´½Ó²»±£´æ£¡');
        }
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëʾÀýÖУ¬ÎÒÃÇÔÚLinks¿ØÖÆÆ÷µÄlinkÒªÁìÖÐʹÓÃÁËÖض¨Ïòµ½Öؽç˵µÄ·ÓɹæÔòÓÖÃûµÄÒªÁì¡£ “$this->redirect(‘link/’.$id);” ʹÓÃÁË·ÓÉÓÖÃû²¢×ª´ïÁ˲ÎÊý£¬ÒÔÌøתµ½Á´½ÓÒ³Ãæ¡£

ÒÔÉϾÍÊÇthinkphp3.2ÔõôʹÓÃÁ¬Ã¦Ìøת¹¦Ð§µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ