PHP code example of zfstarter / zfs-rbac

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

    

zfstarter / zfs-rbac example snippets


'modules' => array(
        'ZFS\Rbac', // <--
        'Application'
    ),

$this->getEventManager()->getSharedManager()->attach(
    ZFS\Rbac\Rbac::EVENT_MANAGER_IDENTIFIER,
    ZFS\Rbac\Rbac::EVENT_GET_CONFIG,
    function () {
        return array(
            'user' => array(
                'permissions' => array(
                    'login'
                )
            ),
            'users_manager' => array(
                'permissions' => array(
                    'modify_users'
                )
            ),
            'admin' => array(
                'children' => array(
                    'users_manager'
                )
            )
        );
    }
);

$this->getEventManager()->getSharedManager()->attach(
    ZFS\Rbac\Rbac::EVENT_MANAGER_IDENTIFIER,
    ZFS\Rbac\Rbac::EVENT_GET_USER_ROLES,
    function () {
        return array('admin');
    }
);

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        if (!$this->isGranted('index_action')) {
            return $this->notFoundAction();
        }
        /* ... */
    }
}

 if ($this->isGranted('buy')): 

$this->getServiceLocator()->get('ZFS\Rbac\Rbac')->isGranted('some_permission');
application.config.php