codeigniter4 / codeigniter4/settings

Return array - multiple result

Open
#54 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
95
Forks
28
PR merge metrics
No merged PRs in 30d

Description

It is possible to get multiple values or an array as result?
e.g. - see code
Get all the settings from a specific key (App.theme) : setting()->get('App.theme','*')
Get all the settings form a specific context : setting()->get('*','user1')
Get all the settings from a specific class : setting()->get('Log')

```
$br='
';

service('settings')->set('App.theme', 'dark', 'user1');
service('settings')->set('App.theme', 'white', 'user2');
service('settings')->set('App.theme', 'red', 'user3');
echo setting()->get('App.theme', 'user1').$br;
echo setting()->get('App.theme', 'user2').$br;
echo setting()->get('App.theme', 'user3').$br;
print_r(setting()->get('App.theme','*')).$br;
print_r(setting()->get('*','user1')).$br;

service('settings')->set('Log.location', 'site/log');
service('settings')->set('Log.date', '20220102');
service('settings')->set('Log.name', 'service');
echo setting()->get('Log.location').$br;
echo setting()->get('Log.date').$br;
echo setting()->get('Log.name').$br;
print_r (setting()->get('Log')).$br;
```

Sample database
```
-- Dumping structure for table ca70_assets.da_settings
CREATE TABLE IF NOT EXISTS `da_settings` (
`class` varchar(255) COLLATE armscii8_bin DEFAULT NULL,
`key` varchar(255) COLLATE armscii8_bin DEFAULT NULL,
`type` varchar(31) COLLATE armscii8_bin DEFAULT NULL,
`context` varchar(255) COLLATE armscii8_bin DEFAULT NULL,
`value` text COLLATE armscii8_bin DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=armscii8 COLLATE=armscii8_bin;

-- Dumping data for table ca70_assets.da_settings: ~11 rows (approximately)
INSERT INTO `da_settings` (`class`, `key`, `type`, `context`, `value`, `created_at`, `updated_at`) VALUES
('Config\\App', 'theme', 'string', 'user1', 'dark', '2023-01-02 16:10:06', '2023-01-02 16:14:10'),
('Config\\App', 'theme', 'string', 'user2', 'white', '2023-01-02 16:10:06', '2023-01-02 16:14:10'),
('Config\\App', 'theme', 'string', 'user3', 'red', '2023-01-02 16:10:06', '2023-01-02 16:14:10'),
('Log', 'location', 'string', NULL, 'site/log', '2023-01-02 16:13:08', '2023-01-02 16:14:10'),
('Log', 'date', 'string', NULL, '20220102', '2023-01-02 16:13:08', '2023-01-02 16:14:10'),
('Log', 'name', 'string', NULL, 'service', '2023-01-02 16:13:08', '2023-01-02 16:14:10');
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the setting()->get() calls shown in the issue and how matching rows in the da_settings table are selected. Verify the wildcard cases for a key, context, and class against the sample data; done means each requested match returns a usable array without changing single-value lookups.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.