PHP code example of myclabs / acl

1. Go to this page and download the library: Download myclabs/acl 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/ */

    

myclabs / acl example snippets


// full configuration shown in the documentation
$acl = new ACL($entityManager);

$acl->grant($user, new ArticleEditorRole($user, $article));

$acl->revoke($user, $role);

$acl->isAllowed($user, Actions::EDIT, $article);

$qb = $entityManager->createQueryBuilder();
$qb->select('article')->from('Model\Article', 'article');

ACLQueryHelper::joinACL($qb, $user, Actions::EDIT);

// This query will return only the articles the user can edit
$articles = $qb->getQuery()->getResult();