尊龙凯时人生就是博

thinkphpÔõôʹÓÃȨÏÞÈÏÖ¤

Ëæ×Å»¥ÁªÍøµÄÒ»Ö±Éú³¤ £¬ÍøÕ¾Óû§ÊýÄ¿Ô½À´Ô½¶à £¬ÎªÁ˸üºÃµØÖÎÀíºÍ°ü¹ÜÓû§Êý¾ÝµÄÇå¾² £¬È¨ÏÞÈÏÖ¤³ÉΪÁËÿ¸öÍøÕ¾±Ø±¸µÄ¹¦Ð§Ö®Ò»  ¡£ÔÚphp¿ò¼ÜÖÐ £¬thinkphpÊÇÒ»¸öÊ®·ÖÊ¢ÐеĿò¼Ü £¬Ò²ÌṩÁËÍêÉƵÄȨÏÞÈÏÖ¤¹¦Ð§  ¡£ÄÇô £¬±¾ÎľÍÀ´ÏêϸÏÈÈÝÒ»ÏÂthinkphpÔõÑùʹÓÃȨÏÞÈÏÖ¤  ¡£

Ò»¡¢È¨ÏÞÈÏÖ¤µÄ×÷ÓÃ

ȨÏÞÈÏÖ¤Ö÷ÒªÊÇΪÁ˶Բî±ð½ÇÉ«µÄÓû§¾ÙÐÐȨÏÞ¿ØÖÆ £¬È·±£Óû§Ö»ÄÜ»á¼û×Ô¼ºÓÐȨ»á¼ûµÄ×ÊÔ´ £¬¶ø²»¿ÉԽȨʹÓà  ¡£ÀýÈç £¬ÔÚÒ»¸öµçÉÌÍøÕ¾ÖÐ £¬ÖÎÀíÔ±¿ÉÒÔÉó²éºÍÖÎÀíËùÓÐÉÌÆ·ÐÅÏ¢ £¬¶øͨË×Óû§Ö»ÄÜä¯ÀÀÉÌÆ·ÐÅÏ¢ £¬²»¿É¾ÙÐÐÐ޸ĺÍɾ³ýµÈ²Ù×÷  ¡£

¶þ¡¢È¨ÏÞÈÏÖ¤µÄʵÏÖ·½·¨

ThinkPHP¿ò¼ÜÌṩÁËÁ½ÖÖȨÏÞÈÏÖ¤µÄʵÏÖ·½·¨£ºRBACºÍ»ùÓÚ½ÚµãµÄȨÏÞÈÏÖ¤  ¡£RBAC£¨Role-Based Access Control£© £¬¼´»ùÓÚ½ÇÉ«µÄ»á¼û¿ØÖÆ £¬½«²î±ðµÄÓû§Æ¾Ö¤Æä½ÇÉ«¾ÙÐзÖÀà  ¡£¶ø»ùÓÚ½ÚµãµÄȨÏÞÈÏÖ¤ £¬ÔòÊÇͨ¹ý½Úµã¾ÙÐÐȨÏÞ¿ØÖÆ £¬½Úµã¿ÉÒÔÊÇ¿ØÖÆÆ÷¡¢²Ù×÷ÒªÁìµÈ  ¡£

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

RBAC

ÔÚ¿ò¼ÜÖÐͨ¹ýRBACʵÏÖȨÏÞÈÏÖ¤ÐèҪʹÓõ½AuthÀà £¬¸ÃÀàλÓÚThinkPHPLibraryThinkÖÐ  ¡£Ïêϸ²Ù×÷°ì·¨ÈçÏ£º

£¨1£©½¨Éè½Úµã±íºÍ½ÇÉ«±í £¬²¢½«È¨ÏÞ½ÚµãºÍ½ÇÉ«¾ÙÐйØÁª  ¡£½¨Éè½Úµã±í¿ÉÒÔ¶ÔÓ¦¿ØÖÆÆ÷ºÍ²Ù×÷ÒªÁì £¬½ÇÉ«±íÔòÊÇÉúÑĽÇÉ«Ãû³ÆºÍ¶ÔÓ¦µÄ½ÚµãID £¬ÈçÏÂËùʾ£º

½Úµã±í£¨think_node£©£º

id name module controller action pid
1 index home index index 0
2 add home index add 1
3 edit home index edit 1
4 delete home index delete 1

½ÇÉ«±í£¨think_role£©£º

id name node_ids
1 admin 1,2,3,4
2 user 1

£¨2£©ÔÚ¿ØÖÆÆ÷ÖÐʹÓÃAuthÀà¾ÙÐÐȨÏÞÈÏÖ¤ £¬Ïêϸ´úÂëÈçÏ£º

class IndexController extends Controller

{

public function __construct()
{
    parent::__construct();
    //ʵÀý»¯AuthÀà
    $auth = new ThinkAuth();

    //»ñÈ¡Ä¿½ñÓû§µÄ½ÇÉ«ID
    $uid = session('user_id');
    //»ñÈ¡Ä¿½ñÇëÇóµÄ¿ØÖÆÆ÷ºÍÒªÁì
    $url = MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME;

    //¾ÙÐÐȨÏÞÈÏÖ¤
    if (!$auth->check($url, $uid)) {
        $this->error('ÄúûÓлá¼û¸ÃÒ³ÃæµÄȨÏÞ£¡');
    }
}

µÇ¼ºó¸´ÖÆ

}

ÉÏÊö´úÂëÖÐ £¬Í¨¹ýʵÀý»¯AuthÀà £¬»ñÈ¡Ä¿½ñÓû§µÄ½ÇÉ«IDºÍÇëÇóµÄ¿ØÖÆÆ÷ºÍÒªÁì £¬ÔÙʹÓÃ$auth->check()ÒªÁì¾ÙÐÐȨÏÞÈÏÖ¤  ¡£ÈôÊÇÑé֤Ƿºà¹ý £¬ÔòÊäÍÉ»¯ÎóÌáÐÑÐÅÏ¢  ¡£

»ùÓÚ½ÚµãµÄȨÏÞÈÏÖ¤

»ùÓÚ½ÚµãµÄȨÏÞÈÏÖ¤¿ÉÒÔʹÓÿò¼ÜÌṩµÄAccessÀàÀ´ÊµÏÖ £¬¸ÃÀàͬÑùλÓÚThinkPHPLibraryThinkÖÐ  ¡£Ïêϸ²Ù×÷°ì·¨ÈçÏ£º

£¨1£©ÔÚ¿ØÖÆÆ÷ÖÐʹÓÃAccessÀà¾ÙÐÐȨÏÞÈÏÖ¤ £¬Ïêϸ´úÂëÈçÏ£º

class IndexController extends Controller

{

public function __construct()
{
    parent::__construct();
    //ʵÀý»¯AccessÀà
    $access = new ThinkAccess();

    //»ñÈ¡Ä¿½ñÓû§µÄ½ÇÉ«ID
    $uid = session('user_id');
    //»ñÈ¡Ä¿½ñÇëÇóµÄ¿ØÖÆÆ÷ºÍÒªÁì
    $url = MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME;

    //½ç˵ȨÏÞ½ÚµãÁбí
    $nodes = array(
        'Index/index',//Ê×Ò³
        'Index/add',//Ìí¼ÓÒ³Ãæ
        'Index/edit',//±à¼­Ò³Ãæ
        'Index/delete',//ɾ³ý²Ù×÷
    );

    //¾ÙÐÐȨÏÞÈÏÖ¤
    if (!$access->check($nodes, $uid, $url)) {
        $this->error('ÄúûÓлá¼û¸ÃÒ³ÃæµÄȨÏÞ£¡');
    }
}

µÇ¼ºó¸´ÖÆ

}

ÉÏÊö´úÂëÖÐ £¬Í¨¹ýʵÀý»¯AccessÀà £¬»ñÈ¡Ä¿½ñÓû§µÄ½ÇÉ«IDºÍÇëÇóµÄ¿ØÖÆÆ÷ºÍÒªÁì £¬ÔÙʹÓÃ$access->check()ÒªÁì¾ÙÐÐȨÏÞÈÏÖ¤  ¡£È¨ÏÞ½ÚµãÁбíÖеÄÿһÏî¶ÔÓ¦Ò»¸ö½Úµã £¬¼´¿ØÖÆÆ÷ºÍÒªÁì  ¡£ÈôÊÇÑé֤Ƿºà¹ý £¬ÔòÊäÍÉ»¯ÎóÌáÐÑÐÅÏ¢  ¡£

Èý¡¢È¨ÏÞÈÏÖ¤µÄÓÅ»¯

ÔÚÏÖʵӦÓÃÖÐ £¬ÎÒÃÇ»¹ÐèÒª¶ÔȨÏÞÈÏÖ¤¾ÙÐÐһЩÓÅ»¯ £¬ÒÔÌá¸ß´úÂëµÄ¸´ÓÃÐÔºÍÇå¾²ÐÔ  ¡£ÏêϸÓÅ»¯µãÈçÏ£º

½¨É蹫¹²¿ØÖÆÆ÷

¿ÉÒÔÔÚ¿ò¼ÜµÄCommonÄ£¿éÖÐ £¬½¨ÉèÒ»¸ö¹«¹²¿ØÖÆÆ÷BaseController £¬½«È¨ÏÞÑéÖ¤Âß¼­°²ÅÅÔڸÿØÖÆÆ÷ÖÐ  ¡£ÆäËû¿ØÖÆÆ÷¼ÌÐø¸Ã¿ØÖÆÆ÷ºó £¬¼´¿ÉÖØÓøò¿·Ö´úÂë  ¡£

»º´æ½ÚµãÐÅÏ¢

ÔÚȨÏÞÈÏÖ¤ÖÐ £¬Ã¿´Î¶¼ÐèÒªÅÌÎʽڵã±íºÍ½ÇÉ«±í £¬»áÓ°ÏìϵͳÐÔÄÜ  ¡£Òò´Ë £¬¿ÉÒÔ½«ÅÌÎÊЧ¹û»º´æÆðÀ´ £¬Ìá¸ßϵͳÐÔÄÜ  ¡£¿ÉÒÔʹÓÿò¼ÜÌṩµÄ»º´æÀà £¬½«ÅÌÎÊЧ¹û»º´æÆðÀ´ £¬Ï´ÎÅÌÎÊʱ £¬Ö±½Ó»ñÈ¡»º´æЧ¹û¼´¿É  ¡£

¼ÓÃܽڵãÐÅÏ¢

ΪÁËÌá¸ßÇå¾²ÐÔ £¬ÎÒÃÇ¿ÉÒÔ¶Ô½ÚµãÐÅÏ¢¾ÙÐмÓÃÜ´¦Àí £¬×èÖ¹Ö±½Ó̻¶½ÚµãÐÅÏ¢  ¡£¿ÉÒÔʹÓÿò¼ÜÌṩµÄ¼ÓÃÜÀà £¬½«½ÚµãID¾ÙÐмÓÃÜ´¦Àí £¬²¢ÔÚ½ÇÉ«±íÖÐÉúÑļÓÃܺóµÄ½ÚµãÐÅÏ¢  ¡£

ËÄ¡¢×ܽá

ȨÏÞÈÏÖ¤ÊÇÍøÕ¾¿ª·¢²»¿Éȱ°±ÉÄÒ»²¿·Ö £¬ËüÄܹ»°ü¹ÜÓû§Êý¾ÝµÄÇå¾² £¬Ìá¸ß¶ÔÓû§µÄÖÎÀí  ¡£¶øÔÚThinkPHP¿ò¼ÜÖÐ £¬Ê¹ÓÃAuthÀàºÍAccessÀà £¬¿ÉÒÔºÜÊÇÀû±ãµØʵÏÖȨÏÞÈÏÖ¤¹¦Ð§  ¡£Í¨¹ý±¾ÎĵÄÏÈÈÝ £¬¸÷ÈË¿ÉÒÔÏàʶµ½ThinkPHPʹÓÃȨÏÞÈÏÖ¤µÄ°ì·¨ºÍÓÅ»¯ÒªÁì £¬ÐÅÍÐÄܹ»¶Ô¸÷È˵Ŀª·¢ÊÂÇéÓÐËù×ÊÖú  ¡£

ÒÔÉϾÍÊÇthinkphpÔõôʹÓÃȨÏÞÈÏÖ¤µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

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