×ðÁú¿­Ê±

thinkphpÔõÑù¾ÙÐÐ×赲·ÓɵIJÙ×÷

Ò»¡¢Ê²Ã´ÊÇ·ÓÉ×èµ²

·ÓÉ×èµ²ÓÃÓÚ¶Ô»á¼û·¾¶¾ÙÐÐÖÎÀíºÍ¿ØÖÆ£¬ÒÔά»¤ÍøÕ¾µÄÇå¾²ÐÔºÍÎȹÌÐÔ¡£ÎªÁ˱ÜÃâÇå¾²ÎÊÌâºÍ¹¥»÷£¬ÎÒÃÇͨ³ £»á¶Ô»á¼û·¾¶¾ÙÐйýÂ˺Íեȡ¡£Í¨¹ý·ÓÉ×èµ²£¬¿ÉÒÔ¶Ô»á¼ûµÄ URL ¾ÙÐпØÖÆ£¬¹ýÂËһЩÎÞЧµÄ URL£¬´Ó¶øÌá¸ßÍøÕ¾µÄÇå¾²ÐԺͿɿ¿ÐÔ¡£

¶þ¡¢ThinkPHP·ÓÉ×赲ʵÏÖÒªÁì

ÒÔÏÂÊÇThinkPHPʵÏÖ·ÓÉ×èµ²µÄÒªÁ죺

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

1.ͨ¹ýÔÚÓ¦ÓÃÉèÖÃÎļþconfig.phpÖÐÉèÖ÷ÓɹæÔò £»

2.ͨ¹ýÔÚ¿ØÖÆÆ÷ŲÓÃ֮ǰ¾ÙÐÐ×èµ²ÅжÏ £»

3.ͨ¹ýÔÚ·ÓÉ֮ǰ¾ÙÐÐ×èµ²ÅжÏ¡£

ÏÂÃæÏêϸÏÈÈÝÕâÈýÖÖÒªÁìµÄʹÓ÷½·¨£º

1.ͨ¹ýÔÚÓ¦ÓÃÉèÖÃÎļþconfig.phpÖÐÉèÖ÷ÓɹæÔò

Ó¦ÓÃÉèÖÃÎļþconfig.phpÖÐÉèÖ÷ÓɹæÔòÊÇThinkPHPÖеÄÒ»ÏЧ¡£ÔÚconfig.phpÎļþÖУ¬¿ÉÒÔÕÒµ½ÃûΪ¡®URL_ROUTE_RULES¡¯µÄÉèÖÃÏ¿ÉÒÔÔÚ¸ÃÉèÖÃÏîÖнç˵·ÓɹæÔò¡£Ïêϸ²Ù×÷ÈçÏ£º

return [
    'URL_ROUTE_RULES' => [
        'login'             => 'Index/login',
        'register'          => 'Index/register',
        'user/:id'          => 'User/index',
        'user/add'          => 'User/add',
        'user/edit/:id'     => 'User/edit',
        'user/delete/:id'   => 'User/delete',
    ],
];

µÇ¼ºó¸´ÖÆ

2.ͨ¹ýÔÚ¿ØÖÆÆ÷ŲÓÃ֮ǰ¾ÙÐÐ×èµ²ÅжÏ

ʹÓÿØÖÆÆ÷À©Õ¹¹¦Ð§¿ÉÒÔÔÚThinkPHPÖÐʵÏÖ·ÓÉ×èµ²¡£ÎÒÃÇ¿ÉÒÔʹÓÃbeforeÒªÁìÔÚ¿ØÖÆÆ÷À©Õ¹¹¦Ð§µÄÀú³ÌÖÐ×èµ²»á¼ûÇëÇó²¢¾ÙÐд¦Öóͷ£¡£Ê¹ÓÃbeforeÒªÁìÐèÒªÖª×ãÒÔÏÂÌõ¼þ£º

1.¿ØÖÆÆ÷ÐèÒª¼ÌÐø\think\ControllerÀà £»

2.beforeÒªÁìÐèÒª·µ»ØÒ»¸öboolÀàÐ͵ÄÖµ£¬trueÌåÏÖ×èµ²Àֳɣ¬falseÌåÏÖ×赲ʧ°Ü¡£

Ïêϸ²Ù×÷ÈçÏ£º

namespace app\index\controller;

use think\Controller;

class Index extends Controller
{
    protected function before()
    {
        if(request()->action() == "index"){
            if(!session('loginTime')){
                return false;
            }
        }
        return true;
    }

    public function index()
    {
        return "hello world";
    }

    public function login()
    {
        return $this->fetch();
    }
}

µÇ¼ºó¸´ÖÆ

3.ͨ¹ýÔÚ·ÓÉ֮ǰ¾ÙÐÐ×èµ²ÅжÏ

ÎÒÃÇ¿ÉÒÔʹÓ÷ÓÉÀ©Õ¹¹¦Ð§ÔÚThinkPHPÖÐʵÏÖ·ÓÉ×èµ²¡£Í¨¹ýʹÓÃbeforeÒªÁ죬ÎÒÃÇ¿ÉÒÔ¶Ô»á¼ûÇëÇó¾ÙÐÐ×èµ²ºÍ´¦Öóͷ££¬´Ó¶øÀ©Õ¹Â·ÓɵĹ¦Ð§¡£Ê¹ÓÃbeforeÒªÁìÐèÒªÖª×ãÒÔÏÂÌõ¼þ£º

1.·ÓÉÐèÒª½ç˵һ¸ö±Õ°üº¯Êý £»

2.beforeÒªÁìÐèÒª·µ»ØÒ»¸öboolÀàÐ͵ÄÖµ£¬trueÌåÏÖ×èµ²Àֳɣ¬falseÌåÏÖ×赲ʧ°Ü¡£

Ïêϸ²Ù×÷ÈçÏ£º

use think\Route;

Route::rule('/', function () {
    return 'hello world!';
}, 'GET')->before(function () {

    if(!session('loginTime')){
        return false;
    }
    return true;
});

µÇ¼ºó¸´ÖÆ

Èý¡¢³£¼û·Óɹýʧ¼°½â¾ö¼Æ»®

1.ÇëÇóµÄÒªÁì²»±»ÔÊÐí

ÍÉ»¯Ôµ¹ÊÔ­ÓÉ£ºÇëÇóµÄÒªÁ첻׼ȷ£¬ÀýÈçʹÓÃgetÇëÇó»á¼ûpost·ÓÉ¡£

½â¾ö¼Æ»®£º¼ì²é·Óɽç˵ºÍÇëÇóÒªÁìÊÇ·ñÒ»Ö¡£

2.δÕÒµ½ÒªÁì½ç˵

ÍÉ»¯Ôµ¹ÊÔ­ÓÉ£ºÇëÇ󷾶ÓëÒªÁ첻ƥÅ䣬»òÕß·ÓɹæÔò½ç˵¹ýʧ¡£

½â¾ö¼Æ»®£º¼ì²é·ÓɹæÔòºÍ½ç˵µÄÒªÁìÃûÊÇ·ñÒ»Ö¡£

3.¿ØÖÆÆ÷²»±£´æ

ÍÉ»¯Ôµ¹ÊÔ­ÓÉ£ºÕÒ²»µ½¶ÔÓ¦µÄ¿ØÖÆÆ÷¡£

½â¾ö¼Æ»®£º¼ì²é¿ØÖÆÆ÷ÀàÃûºÍÎļþÃûÊÇ·ñÒ»Ö£¬ÒÔ¼°ÊÇ·ñÔÚ׼ȷµÄλÖá£

4.ȱÉÙ²ÎÊý

ÍÉ»¯Ôµ¹ÊÔ­ÓÉ£ºÇëÇ󷾶ÖÐȱÉÙÐëÒªµÄ²ÎÊý¡£

½â¾ö¼Æ»®£º¼ì²é·ÓɹæÔòÊÇ·ñ½ç˵׼ȷ£¬²¢×ª´ï׼ȷµÄ²ÎÊý¡£

5.¡°Access Denied¡±¹ýʧ

ÍÉ»¯Ôµ¹ÊÔ­ÓÉ£ºÈ¨ÏÞȱ·¦£¬»òÕßÒѾ­Í˳öµÇ¼¡£

½â¾ö¼Æ»®£º¼ì²éȨÏÞÉèÖú͵Ǽ״̬µÈÐÅÏ¢¡£

×¢£ºÒÔÉϹýʧ½öÊdz£¼û¹ýʧ£¬Ïêϸ¹ýʧ»¹ÒªÆ¾Ö¤ÏêϸÇéÐξÙÐÐÅŲé¡£

ÒÔÉϾÍÊÇthinkphpÔõÑù¾ÙÐÐ×赲·ÓɵIJÙ×÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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