PHP code example of loadsys / cakephp-auth-userentity
1. Go to this page and download the library: Download loadsys/cakephp-auth-userentity 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/ */
loadsys / cakephp-auth-userentity example snippets
$this->loadComponent('Auth', [
/**
* Name the plugin's Component as the class to use. This is **me the Entity class that will be used as the container for the
* array data in Auth->user(). Defaults to `\Cake\ORM\Entity`, which
* is safe for all apps, but will exclude any custom logic you may
* have defined in your app's "user" Entity class.
*/
'entityClass' => '\App\Model\Entity\User',
/**
* Any options to pass to the new Entity when it is created. The defaults
* are:
*
* [
* 'markClean' => true, // Force the Entity to appear clean.
* 'source' => 'AuthUser', // The repository this record originated from.
* // We default to a fake name to make it clear
* // the Entity doesn't represent a "true" ORM
* // record.
* ]
*/
'entityOptions' => [
'associated' => ['Permissions', 'Groups'],
],
/**
* (The rest of your normal Auth configs follow here.)
*/
// ...
]);
// Get the whole entity:
$user = $this->Auth->userEntity();
// Or to get a specific property (which will engage any
// _getProperty() methods you have defined in your Entity class):
$userEmail = $this->Auth->userEntity('email');
// Internally, the Entity::get() interface is used, so you can pass
// nested keys (but remember that this data must be loaded into the
// Auth session data!):
$groupName = $this->Auth->userEntity('group.name');
// Or to call a function from your entity:
if (!$this->Auth->userEntity()->isAdmin()) {
$this->Flash->error('Only admins can use this method.');
return $this->redirect('/');
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.