barbierp35 / reconnexion-bar
CakePHP 的 ReconnexionBar 插件
2.0.8
2021-07-05 06:50 UTC
Requires
- cakephp/cakephp: ^4.0
Requires (Dev)
- phpunit/phpunit: ^5.7.14|^6.0
README
安装
此插件可以帮助您连接到另一个账户并在父账户中重新连接。当您连接到另一个账户时,它会在您应用程序所有页面的底部显示一个红色栏以重新连接到父账户。
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方式
CakePHP 3
composer require barbierp35/reconnexion-bar "^1.0.0"
CakePHP 4
composer require barbierp35/reconnexion-bar "^2.0.0"
然后,您需要在 src/Application.php
文件的 bootstrap 方法中加载此插件。
$this->addPlugin('ReconnexionBar');
或者您可以使用控制台来自动完成此操作。
bin/cake plugin load ReconnexionBar
配置
可选,您可以在 bootstrap.php 文件中更改配置
Configure::write('ReconnexionBar', [
'column_name' => 'first_name', // Name of the column (string). You can use a virtual field for more customization
'linkActionReconnectParentAccount' => [ // Url of action to reconnect on parent account
'prefix' => false,
'plugin' => false,
'controller' => 'Users',
'action' => 'reconnectParentAccount'
],
'optionsQuery' => ['contain' => ['Roles']], // default = null. Possibility to add options in the Users query to reconnect to parent account
'style' => [
'type' => 'bar', // bar or circle
'position' => 'bottom', // For bar : bottom or top. For circle : top-left, top-right, bottom-left or bottom-right
'color' => '#e63757' // Color of the bar or circle
]
]);
您必须加载 ReconnexionBar 组件,创建两个操作并编辑注销操作以使用此插件。例如,在 UsersController.php 文件中
public function initialize(): void
{
parent::initialize();
$this->loadComponent('ReconnexionBar.Reconnexion');
}
/**
* Action to connect on another account
*/
public function connectOtherAccount($userId)
{
$user = $this->Users->get($userId);
$this->Reconnexion->connectOtherAccount($user);
}
/**
* Action to reconnect on the parent account
*/
public function reconnectParentAccount()
{
$this->Reconnexion->reconnectParentAccount();
}
public function logout()
{
$this->Reconnexion->deleteReconnectSession();
...
}