2017 © Pedro Peláez
 

cakephp-plugin cake-oc

OCClient plugin for CakePHP

image

alvarium/cake-oc

OCClient plugin for CakePHP

  • Friday, December 15, 2017
  • by elboletaire
  • Repository
  • 0 Watchers
  • 4 Stars
  • 133 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 202 % Grown

The README.md

OCClient plugin for CakePHP

A CakePHP 3.X plugin for the OpenComponents PHP Client, (*1)

Installation

You can install this plugin into your CakePHP application using composer., (*2)

The recommended way to install composer packages is:, (*3)

composer require alvarium/cake-oc

Configuration

After that, load the plugin in your bootstrap.php file:, (*4)

Plugin::load('Alvarium/OCClient', ['bootstrap' => true]);

Create a file named occlient.php in your config folder defining your open-components registry endpoint:, (*5)

<?php

return [
    'OCClient' => [
        'serverRendering' => 'https://registry.your-company.io/',
    ]
];

Then, load the component + the helper in the controller(s) where you want the plugin to be used:, (*6)

<?php
namespace App;

use Cake\Event\Event;

class PostsController extends AppController
{
    public function initialize()
    {
        parent::initialize();

        $this->loadComponent('Alvarium/OCClient.Client');
    }

    public function beforeRender(Event $event)
    {
        parent::beforeRender($event);

        $this->viewBuilder()->helpers([
            'Alvarium/OCClient.OC',
        ]);
    }
}

Usage

After all configuration has been done, and having both component and helper loaded, to load your opencomponents scripts in your pages you just need to define the components using setComponents in your controller method:, (*7)

<?php
namespace App;

// [...]

class PostsController extends AppController
{
    // [...]

    public function index()
    {
        $this->Client->setComponents([
            [
              'name' => 'your-awesome-component',
              'parameters' => [
                  'comp1_selector' => '#awesome-component',
                  'key' => 'value',
                  'key2' => 'value2',
              ],
            ],
            [
                'name' => 'another-awesome-component',
                'parameters' => [
                    'comp2_selector' => '#awesome-component-2',
                    'key12' => 'value12',
                    'key23' => 'value23',
                ]
            ]
        ]);
    }

Note how we define the *_selector key. That's because we're able to define our selectors for each component (meaning we need to define a layer with the appropriated selector in the view for each component)., (*8)

That's in part because this plugin's helper loads components appending them to the script view block. Depending on how do you work with your opencomponent widgets this could bring some issues., (*9)

If so, you can just avoid using the helper and add the scripts wherever you want:, (*10)

foreach ($oc_components as $component) {
    echo $component;
}

License

This plugin code is licensed under a GNU GPL v.3 license., (*11)

The Versions

15/12 2017

dev-master

9999999-dev

OCClient plugin for CakePHP

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

15/12 2017

3.0.2

3.0.2.0

OCClient plugin for CakePHP

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

15/12 2017

3.0.1

3.0.1.0

OCClient plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

15/12 2017

dev-cake-1.3

dev-cake-1.3

OCClient plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

15/12 2017

1.3.1

1.3.1.0

OCClient plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

15/12 2017

1.3.0

1.3.0.0

OCClient plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires

15/12 2017

3.0.0

3.0.0.0

OCClient plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires