solophp/settings
最新稳定版本:v2.0.0
Composer 安装命令:
composer require solophp/settings
包简介
Managing application settings stored in a database
关键字:
README 文档
README
A simple and efficient PHP settings management package that provides an interface to store and retrieve application settings from a database.
Features
- Easy integration with existing database connections
- Automatic serialization and deserialization of complex data types
- Support for both object-oriented and array-like access to settings
- Efficient caching of settings to minimize database queries
Installation
composer require solophp/settings
Requirements
- PHP 8.1+
- PDO extension
Basic Setup
First, ensure that you have a table for storing settings. The table should have two columns: name (string) and value (string).
Example table schema:
CREATE TABLE `settings` ( `name` VARCHAR(255) NOT NULL, `value` TEXT NOT NULL, PRIMARY KEY (`name`) );
Usage
First, create an instance of the Settings class:
use Solo\Settings\Settings; $pdo = new PDO('mysql:host=localhost;dbname=app', 'user', 'pass'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $settings = new Settings($pdo, 'settings');
Retrieving Settings
You can retrieve settings using either method calls or property access:
$value = $settings->get('my_setting'); // or $value = $settings->my_setting;
Storing Settings
Similarly, you can store settings using either method calls or property access:
$settings->set('my_setting', 'new_value'); // or $settings->my_setting = 'new_value';
Get all Settings
Get all settings as an associative array.:
$settings->getAll();
License
This project is licensed under the MIT License - see the LICENSE file for details.
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-18