cakesuit/option 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cakesuit/option

Composer 安装命令:

composer require cakesuit/option

包简介

Define/fetching quickly preference for your application

README 文档

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

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固