定制 simpleteam/craft-toolkit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

simpleteam/craft-toolkit

最新稳定版本:0.9.2

Composer 安装命令:

composer require simpleteam/craft-toolkit

包简介

A comprehensive toolkit for Craft CMS - provides options, utilities, and enhanced functionality

README 文档

README

A comprehensive toolkit for Craft CMS that provides complementary functionality and utilities. Currently includes an options system for easy key-value storage accessible via Craft::$app->options.

Installation

composer require simpleteam/craft-toolkit
# Activation on DDEV
ddev craft plugin/install simpleteam-craft-toolkit

The plugin will automatically register the options component when installed.

Usage

Once installed, you can use the options component anywhere in your Craft application:

Store a value

Craft::$app->options->set('my_key', 'my_value');

// Store complex data (automatically will be JSON encoded)
Craft::$app->options->set('user_preferences', [
    'theme' => 'dark',
    'language' => 'en',
    'notifications' => true
]);

Retrieve a value

$value = Craft::$app->options->get('my_key');

// With default value
$theme = Craft::$app->options->get('my_key', 'some_default_value');

Check if option exists

if (Craft::$app->options->exists('my_key')) {
    // Option exists
}

// Or use the alias
if (Craft::$app->options->has('my_key')) {
    // Option exists
}

Delete an option

Craft::$app->options->delete('my_key');

Get all options

$allOptions = Craft::$app->options->getAll();

// Get only autoload options
$autoloadOptions = Craft::$app->options->getAll(true);

Set multiple options

Craft::$app->options->setMultiple([
    'option1' => 'value1',
    'option2' => 'value2',
    'option3' => ['complex' => 'data']
]);

Features

Options System

  • Automatic Installation: No manual configuration required
  • WordPress-like API: Familiar interface for WordPress developers
  • JSON Support: Automatically handles complex data types
  • Database Storage: Uses a dedicated table with proper indexing
  • Autoload Support: Option to mark frequently used options for caching
  • Clean Syntax: Available anywhere via Craft::$app->options

Database

The plugin automatically creates a simple_options table with the following structure:

  • id - Primary key
  • key - Option key (unique index)
  • value - Option value (longtext)
  • isJson - Boolean flag for JSON data
  • autoload - Boolean flag for autoloading
  • dateCreated - Creation timestamp
  • dateUpdated - Last update timestamp

Requirements

  • Craft CMS 5.0 or later
  • PHP 8.0 or later

License

MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-09