ovidiupop/yii2-identities

"identities" 模块旨在管理和操作与身份相关联的信息,这些身份可以是个人或公司。它提供了处理这些实体相关数据、显示和操作的功能。

安装: 6

依赖项: 0

建议者: 0

安全: 0

星级: 0

关注者: 1

分支: 1

开放问题: 0

类型:yii2-extension

dev-main 2024-01-11 19:43 UTC

This package is auto-updated.

Last update: 2024-09-11 21:07:35 UTC


README

"identities" 模块旨在管理和操作个人和公司相关的信息。它提供了处理相关数据、显示和执行操作的功能。

安装

推荐安装方法是使用 Composer。

composer require --prefer-dist ovidiupop/yii2-identities "@dev"

或者,将以下行添加到您的 composer.json 文件中

"ovidiupop\yii2-identities": "@dev"

配置

运行位于 migrations 文件夹中的迁移来创建必要的表。

在 config/main.php 文件中添加

'modules' => [
    'identities' => [
        'class' => 'ovidiupop\identities\IdentitiesModule',
    ],
],

用法

要管理单页上的所有实体而无需定制,请访问 /identities/identity/index。在这里,您可以添加、更新和删除个人和公司身份。

定制

该模块使用标准的 Yii2 组件(GridView 和 DetailView),并且设计遵循默认样式。

对于定制,以下配置是可用的

完全定制的示例

'modules' => [
    'identities' => [
        'class' => 'ovidiupop\identities\IdentitiesModule',
        'addressFormCustom' => '@backend/identities_custom/custom_address_form',
        'form' => '@backend/identities_custom/_form_identity',
        'formPersonCompany' => '@backend/identities_custom/form_person_company',
        'view' => '@backend/identities_custom/view_identity',
        'index' => '@backend/identities_custom/index_identity',
        --------------------- .php is required ----------------
        'columns' => '@backend/identities_custom/columns.php',
        'gridConfig' => '@backend/identities_custom/grid_config.php',
        'gridConfigPersons' => '@backend/identities_custom/grid_config_persons.php',
        'gridConfigCompanies' => '@backend/identities_custom/grid_config_companies.php',
        ]
    ..................

当然,所有路径只是示例,但您可以使用任何路径来存放自定义文件。
要开始定制,将模块的文件(或从定制文件夹)复制到您的项目文件夹,然后根据需要进行个性化设置。

定制细节

addressFormCustom - the file where the address data collection form is configured.
form - the file for creating and updating new identities.
formPersonCompany - the file for customizing forms for persons and companies.
view - the view file.
index - the index file for accessing the grid of registered identities.
columns - if using custom grids (e.g., kartik/Grid), prepare the grid columns accordingly.
gridConfig - the file where the order and visibility of grid columns are set.
gridConfigPersons - when displaying only entities of type Person, set the order and visibility of grid columns.
gridConfigCompanies - when displaying only entities of type Company, set the order and visibility of grid columns.

在 index_identity.php 文件中,获取网格的列如下

// For all columns
$columns = Yii::$app->getModule('identities')->getColumnsForGrid($searchModel, $dataProvider);

// For separate entities in the index, add an extra parameter "$columnsForType" received from the controller.
$columns = Yii::$app->getModule('identities')->getColumnsForGrid($searchModel, $dataProvider, $columnsForType);

要分别管理特定的身份,请在您的项目中为每个人和公司创建一个控制器。控制器应使用 IdentitiesTrait。一个完整的控制器应如下所示

    <?php
    namespace backend\controllers;

    use ovidiupop\identities\interfaces\IdentitiesTrait;
    use ovidiupop\identities\models\IdentityData;
    use yii\web\Controller;

    class PersonsController extends Controller
    {
        use IdentitiesTrait;

        /**
        * REQUIRED: The is the type of managed entity
        * (IdentityData::PERSON = 1, IdentityData::COMPANY = 2)
        * @var int
        */
        public $type = IdentityData::PERSON;

        /**
        * Optional: allows sending parameters to the index file for customizing the grid based on preferences.
        * * in index.php you can use like this: 'panelHeadingIcon' => $config['icon'] ?? ICON_IDENTITY,
        *
        * @var array
        */
        public $gridData = ['icon'=>ICON_GALLERY];
    }

对于消息翻译,请使用 'identities' 约定 [Yii::t('identities', message)]。

就这样!享受吧!