PHPackages                             aiphee/related-content - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. aiphee/related-content

ActiveCakephp-plugin[Framework](/categories/framework)

aiphee/related-content
======================

RelatedContent plugin for CakePHP

0.0.3(10y ago)012[1 PRs](https://github.com/aiphee/cakephp-related-content/pulls)PHPPHP &gt;=5.4.16

Since Jan 21Pushed 8y ago1 watchersCompare

[ Source](https://github.com/aiphee/cakephp-related-content)[ Packagist](https://packagist.org/packages/aiphee/related-content)[ RSS](/packages/aiphee-related-content/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (4)Versions (5)Used By (0)

[![Build Status](https://camo.githubusercontent.com/c4efa569cfd573d339086bebd567691c010cc12bfdf50aeedefa5408fd6b7a0b/68747470733a2f2f7472617669732d63692e6f72672f6169706865652f63616b657068702d72656c617465642d636f6e74656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/aiphee/cakephp-related-content)

Related content plugin for CakePHP 3
====================================

[](#related-content-plugin-for-cakephp-3)

[![Autocomplete](/related1.png "Autocomplete")](/related1.png)[![Related view](/related2.png "Related view")](/related2.png)

This is a fast made plugin made for simple maintaining of relationships.

You can define that one entry in table has similar entries in other tables.

It also has basic element with ajax which relies on `Bootstrap 3`.

Please, be noted that this is not a complex plugin, there may be serious bugs, you are welcome to report or repair them.

Installation
------------

[](#installation)

- Run migration from plugin or create table manually.

```
CREATE TABLE `related_contents` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `source_table_name` varchar(255) DEFAULT NULL COMMENT 'Table which you link from',
  `target_table_name` varchar(255) DEFAULT NULL COMMENT 'Table which you link to',
  `source_table_id` int(11) NOT NULL COMMENT 'ID of table you link from',
  `target_table_id` int(11) NOT NULL COMMENT 'ID of table you link to',
  `created` datetime NOT NULL,
  PRIMARY KEY (`id`)
)
```

- Copy repo content to plugins directory and add to your cakephp composer.json

```
    "autoload": {
        "psr-4": {
            "App\\": "src",
            "RelatedContent\\": "./plugins/RelatedContent/src",
        }
    }

```

or use packagist `composer require aiphee/related-content`

- Add to your `bootstrap.php`

```
Plugin::load('RelatedContent', ['routes' => true]);
```

Usage
-----

[](#usage)

- add first behavior to your table for it to be searchable (added to cache for search)

```
$this->addBehavior('RelatedContent.InRelatedIndex');
```

- add second behavior which will have Similar

```
$this->addBehavior('RelatedContent.HasRelated', isset($config['options']) ? $config['options'] : []);
```

- Add element to your view

```
