Skip to content

Commit 6858424

Browse files
committed
Closure integration for options
1 parent de22548 commit 6858424

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ select-box with the given options.
8989
- `editable` - Bool if the setting should be editable.
9090
- `weight` - Weight (order) of the setting.
9191

92+
The options key can handle multiple types. You can define an array with options, but you can also create a close to
93+
prevent long queries on every request. Example:
94+
95+
```php
96+
Setting::register('App.Index', false, [
97+
'options' => function() {
98+
return TableRegistry::get('Blogs')->find('list')->toArray();
99+
}
100+
]);
101+
```
102+
92103
## Using the setting-forms
93104

94105
If you are using the [CakeManager-Plugin](https://github.com/cakemanager/cakephp-cakemanager), we will create a default form where you can edit your settings (if the field `editable` isset to `1`). The Settings-Plugin will automatically add a menu-item to the admin-area.

src/Model/Entity/Configuration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ protected function _getKey()
7373
protected function _getOptions()
7474
{
7575
if (array_key_exists('name', $this->_properties)) {
76-
return Setting::options($this->_properties['name']);
76+
$options = Setting::options($this->_properties['name']);
77+
if (is_callable($options)) {
78+
return $options();
79+
}
80+
return $options;
7781
}
7882
return false;
7983
}

0 commit comments

Comments
 (0)