2017 © Pedro PelĂĄez
 

cakephp-plugin option

Define/fetching quickly preference for your application

image

cakesuit/option

Define/fetching quickly preference for your application

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Cakesuit/Option plugin for CakePHP

What is it ?

This plugin allows you to simply define options for your application with the key/value pair., (*1)

Requirements

  • CakePHP 3.4.0+
  • PHP 5.6+

Installation

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

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

composer require cakesuit/option

Load plugin in config/bootstrap.php application, (*4)

bin/cake plugin load Cakesuit/Option

If you want to use the built-in routes, load the plugin as follows, (*5)

bin/cake plugin load -r Cakesuit/Option

Migration

Now that the plugin is installed and loaded, you have to migrate the schema for the database, (*6)

bin/cake migrations migrate -p Cakesuit/Option

Default Routes

<?php
Router::plugin(
    'Cakesuit/Option',
    ['path' => '/cakesuit'],
    function (RouteBuilder $routes) {

        // List all
        $routes->connect(
            'options', 
            [
                'controller' => 'Options', 
                'action' => 'index'
            ]
        );

        // Add
        $routes->connect(
            'options', 
            [
                'controller' => 'Options', 
                'action' => 'add'
            ]
        );

        // Edit
        $routes->connect(
            'options/edit/:id', 
            [
                'controller' => 'Options', 
                'action' => 'edit', 
                [
                    'id' => '[0-9]+',
                    'pass' => ['id']
                ]
            ]
        );

        // Show
        $routes->connect(
            'options/view/:id', 
            [
                'controller' => 'Options', 
                'action' => 'view', 
                [
                    'id' => '[0-9]+',
                    'pass' => ['id']
                ]
            ]
        );

        // Delete
        $routes->connect(
            'options/delete/:id', 
            [
                'controller' => 'Options', 
                'action' => 'delete', 
                [
                    'id' => '[0-9]+',
                    'pass' => ['id']
                ]
            ]
        );

    }
);

Database

Here is an example of what can be found in the table, (*7)

key value autoload
site_name My Blog 1
site_description Use CakeSuit/Option for advance settings 1
analytics_ua UA-XXXXXX 0

How to us ?

Recover all data marked autoload, (*8)

<?php
// Load the Model if necessary
$this->loadModel('Options');

// Fetch all data marked autoload
$options = $this->Options->find('autoload');
echo $options->site_name; // = 'My Blog'
echo $options->site_description; // = 'Use CakeSuit/Option for advance settings'
echo $options->analytics_ua; // = null (this value does not exist)

Recover data by keys, (*9)

<?php
// Load the Model if necessary
$this->loadModel('Cakesuit/Option.Options');
$options = $this->Options->find('keys', [
    'keys' => ['analytics_ua', 'site_description']
]);
echo $options->site_name; // = null
echo $options->site_description; // = 'Use CakeSuit/Option for advance settings'
echo $options->analytics_ua; // = 'UA-XXXXXX'

Check if empty data, (*10)

<?php
// Load the Model if necessary
$this->loadModel('Cakesuit/Option.Options');

$options = $this->Options->find('keys', [
    'keys' => ['no_exists_value']
]);
$options->isEmpty(); // = true

Count data, (*11)

<?php
// Load the Model if necessary
$this->loadModel('Cakesuit/Option.Options');

$options = $this->Options->find('autoload');
echo $options->count(); // = 2

...

If you encounter any difficulties, contact me. Thank you., (*12)

C@kesuit, (*13)

The Versions

21/11 2017

dev-master

9999999-dev

Define/fetching quickly preference for your application

  Sources   Download

MIT

The Requires

 

The Development Requires

21/11 2017

1.1.1

1.1.1.0

Define/fetching quickly preference for your application

  Sources   Download

MIT

The Requires

 

The Development Requires

03/10 2017

1.1.0

1.1.0.0

Define/fetching quickly preference for your application

  Sources   Download

MIT

The Requires

 

The Development Requires

02/10 2017

1.0.0

1.0.0.0

CakeSuit/Option plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires