cakesuit / option
Define/fetching quickly preference for your application
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:cakephp-plugin
Requires
- cakephp/cakephp: ^3.4
Requires (Dev)
- phpunit/phpunit: ^5.7|^6.0
This package is not auto-updated.
Last update: 2025-04-27 07:41:24 UTC
README
What is it ?
This plugin allows you to simply define options for your application with the key/value pair.
Requirements
- CakePHP 3.4.0+
- PHP 5.6+
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require cakesuit/option
Load plugin in config/bootstrap.php application
bin/cake plugin load Cakesuit/Option
If you want to use the built-in routes, load the plugin as follows
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
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
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
<?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
<?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
<?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
<?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.
C@kesuit