1. Go to this page and download the library: Download casbin/think-adapter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
casbin / think-adapter example snippets
use Casbin;
// 给用户alice赋予对data1的read权限
Casbin::addPolicy('alice', 'data1', 'read');
use Casbin;
$sub = 'alice'; // the user that wants to access a resource.
$obj = 'data1'; // the resource that is going to be accessed.
$act = 'read'; // the operation that the user performs on the resource.
if (true === Casbin::enforce($sub, $obj, $act)) {
// permit alice to read data1
echo 'permit alice to read data1';
} else {
// deny the request, show an error
}
php think casbin:publish
php think casbin:migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.