lrnzfrr/custom-fields

CustomFields plugin for CakePHP

Installs: 24

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:cakephp-plugin

v0.0.1 2019-03-26 11:13 UTC

This package is auto-updated.

Last update: 2024-04-29 04:13:11 UTC


README

With this plugin you can easy add custom fields to all your records!

Installation

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

composer require lrnzfrr/custom-fields

Load the plugin:

bin/cake plugin load lrnzfrr/CustomFields

Use the Plugin

First of all be sure your entity has custom_fields accessible

Launch migration for the plugin:

bin/cake migrations migrate -p lrnzfrr/CustomFields

Add the behavior in Model Table:

        $this->addBehavior('lrnzfrr/CustomFields.CustomFieldable',
                          ['accessibleFields'=>['article_type','article_status']  // custom fields accessible
                          ]);

Use the finder method in Controller:

    $articles = $this->Articles->find('withCustomFields');

in the view:

        echo $this->Form->hidden('custom_fields.0.name',['value'=>'article_type']);
        echo $this->Form->text('custom_fields.0.value',['value'=>'','label'=>'article_type','placeholder'=>'Article Type']);

        echo $this->Form->hidden('custom_fields.1.name',['value'=>'article_status']);
        echo $this->Form->text('custom_fields.1.value',['value'=>'','label'=>'article_status','placeholder'=>'Article Status']);

If you prefer you can also get the custom fields inside entity with assoc key => value with getCustomFieldsAssoc method:

inside entity:

use lrnzfrr\CustomFields\Model\Traits\CustomFieldTrait;

class ....
use CustomFieldTrait;
protected $_virtual = ['custom_fields_assoc'];

    /*
    ** Create a virtual property with custom Fields
    */
    protected function _getCustomFieldsAssoc()
    {
        return $this->getCustomFieldsAssoc();
    }

That's all!

composer

cakephp

flor.it