barbierp35/reconnexion-bar

CakePHP 的 ReconnexionBar 插件

安装次数: 1,125

依赖项: 0

建议者: 0

安全性: 0

星标: 1

关注者: 2

分支: 1

开放性问题: 0

类型:cakephp-plugin

2.0.8 2021-07-05 06:50 UTC

This package is auto-updated.

Last update: 2024-09-05 14:14:53 UTC


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();
    ...
}