1. Go to this page and download the library: Download rootwork/phalcon-extras 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/ */
rootwork / phalcon-extras example snippets
cp acl.example.php app/config/acl.php
/**
* Setup the auth component
*/
$di->setShared('auth', function () {
/** @var \Phalcon\Config $aclConfig */
$aclConfig = terAllowed', function (Event $event, AuthComponent $auth) {
if ($auth->persistent->role == 'Guest') {
return true; // If the ACL allows a Guest at this route, no additional steps
}
// Load authorized user from the DB
if ($user = User::findFirstById($auth->persistent->userId)) {
$auth->di->setShared('user', $user);
return true;
}
return false;
});
$eventsManager->attach('auth:afterDenied', function (Event $event, AuthComponent $auth) {
// Redirect unathorized users
$auth->response->redirect('/login');
$auth->response->send();
return false;
});
$auth->setEventsManager($eventsManager);
return $auth;
});
/**
* Register a dispatcher
*/
$di->setShared('dispatcher', function () use ($config, $di) {
$eventsManager = new EventsManager();
$eventsManager->attach('dispatch:beforeExecuteRoute', $di->get('auth'));
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('App\Controller');
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
/**
* Make the current user available to the app
*/
$di->setShared('user', function () {
return null;
});
// In a login action...
$auth = $this->getDI()->get('auth');
$auth->setRole($user->role);
// Optional persisted auth data
$auth->persistent->userId = $user->id;
$auth->persistent->name = $user->name;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.