2017 © Pedro Peláez
 

cakephp-plugin related-content

RelatedContent plugin for CakePHP

image

aiphee/related-content

RelatedContent plugin for CakePHP

  • Friday, September 15, 2017
  • by aiphee
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Related content plugin for CakePHP 3

Autocomplete Related view, (*2)

This is a fast made plugin made for simple maintaining of relationships., (*3)

You can define that one entry in table has similar entries in other tables., (*4)

It also has basic element with ajax which relies on Bootstrap 3., (*5)

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

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, (*7)

  • Add to your bootstrap.php
Plugin::load('RelatedContent', ['routes' => true]);

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
<?= $this->element('RelatedContent.managingRelated', ['tables_to_get' => ['ContentNews', 'ContentPages']]) ?>

Parameter tables_to_get is optional, it will allow to search just in some tables., (*8)

  • To get related content with your entry, you have to pass parameter to find
$entity = $this->ContentPages->get($id, [
                'getRelated' => true
            ]);
  • You can also use element in view, which model does not have HasRelated behavior, to populate some fields (target_table_name and target_table_id are directly in table)
<?= $this->element('RelatedContent.foreignTableSearch') ?>
<?= $this->Form->input('foreign_table_id', ['type' => 'hidden']) ?>
<?= $this->Form->input('foreign_table_name', ['type' => 'hidden']) ?>

It looks like this then:, (*9)

Managing related without associations, (*10)

The Versions

15/09 2017

dev-add-code-of-conduct-1

dev-add-code-of-conduct-1

RelatedContent plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

11/02 2016

dev-master

9999999-dev

RelatedContent plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

11/02 2016

0.0.3

0.0.3.0

RelatedContent plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

21/01 2016

0.0.2

0.0.2.0

RelatedContent plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

21/01 2016

0.0.1

0.0.1.0

RelatedContent plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires