定制 angelxmoreno/cakephp-linked-entities 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

angelxmoreno/cakephp-linked-entities

Composer 安装命令:

composer require angelxmoreno/cakephp-linked-entities

包简介

LinkedEntities plugin for CakePHP 3.x

README 文档

README

Build Status Codacy Badge Maintainability Test Coverage License Minimum CakePHP Version Minimum PHP Version

LinkedEntities allows the ability to associate your User Entities with any other Entities ( including self referencing ) by a category type. It adds shortcut functions to your User Table for ease of use.

Features

  • Ability to define User-to-Entity relationship via a polymorphic table
  • Define relationship by category
  • Automatic relationship of Entity-to-User
  • Shortcut methods based on relationship name

Examples

$this->Users->addStarredProject($user, $project);
$this->Users->removeFollowedUser($user, $otherUser);

Requirements

  • CakePHP 3.x
  • PHP >=5.6

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require angelxmoreno/cakephp-linked-entities

Next you need to load the plugin by adding the following to your config/bootstrap.php file:

// config/bootstrap.php
Plugin::load('LinkedEntities', ['bootstrap' => true]);

Finally, create the required tables using cakephp/migrations:

bin/cake migrations migrate -p LinkedEntities

Or import the sql schema found in config/schema.

Setup

  1. In your config/app.php define a new config key called LinkedEntities ( see configuration )
  2. In your UsersTable add the LinkedEntities.LinkableEntityUser behavior like so:
$this->addBehavior('LinkedEntities.LinkableEntityUser');
  1. Optionally add the LinkedEntities.LinkableEntity behavior to the corresponding Table classes defined in your config. i.e:
$this->addBehavior('LinkedEntities.LinkableEntity');

Configuration

Sample configuration:

// config/app.php
'LinkedEntities' => [
    'UserModel' => 'Users',
    'link_types' => [
        'star' => 1,
        'follow' => 2,
    ],
    'links' => [
        'StarredProjects' => [
            'name' => 'UserStars',
            'className' => 'Projects',
            'linkType' => 1
        ],
        'FollowedProjects' => [
            'name' => 'Followers',
            'className' => 'Projects',
            'linkType' => 2
        ],
        'FollowedUsers' => [
            'name' => 'Followers',
            'className' => 'Users',
            'linkType' => 2
        ]
    ]
]

With the configuration above ( after adding the behavior ) you will have 6 new methods available to your UsersTable:

  1. $this->Users->addStarredProjects($user, $project);
  2. $this->Users->removeStarredProjects($user, $project);
  3. $this->Users->addFollowedProjects($user, $project);
  4. $this->Users->removeFollowedProjects($user, $project);
  5. $this->Users->addFollowedUsers($user, $otherUser);
  6. $this->Users->removeFollowedUsers($user, otherUser);

UserModel parameter

A string defining the plugin.name of your UsersTable ( defaults to Users )

link_types

An array as a int => string ( this saves the int provided under the table column type )

links

An array as relationship name => settings Settings have the following keys

  • name: The name of the relationship from the perspective of the linked entity ( the reverse relationship name )
  • className: The name of the table to associate the user to
  • linkType: the int value corresponding to one of the defined link_types

Reporting Issues

If you have a problem with the plugin please open an issue on GitHub.

License

This plugin is offered under an MIT license.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固