|
@@ -288,23 +288,26 @@ class Model
|
|
|
}
|
|
|
public function value($key, $value = false, $col = 'id,name')
|
|
|
{
|
|
|
- if (isset($this->config['struct'][$key]) && $option = Dever::issets($this->config['struct'][$key], 'value')) {
|
|
|
- if (isset($this->config['struct'][$key]['option'])) {
|
|
|
- $option = $this->config['struct'][$key]['option'];
|
|
|
- } else {
|
|
|
- if (is_string($option) && strpos($option, 'Dever') === 0) {
|
|
|
- eval('$option=' . $option . ';');
|
|
|
- } elseif (is_string($option)) {
|
|
|
- $option = Dever::db($option)->select([], ['col' => $col]);
|
|
|
- } elseif (is_array($option) && !isset($option[0])) {
|
|
|
- $temp = $option;
|
|
|
- $option = array();
|
|
|
- $col = explode(',', $col);
|
|
|
- foreach ($temp as $k => $v) {
|
|
|
- $option[] = array($col[0] => $k, $col[1] => $v);
|
|
|
- }
|
|
|
+ if (isset($this->config['option'][$key])) {
|
|
|
+ $option = $this->config['option'][$key];
|
|
|
+ } elseif (isset($this->config['struct'][$key])) {
|
|
|
+ $option = Dever::issets($this->config['struct'][$key], 'option');
|
|
|
+ if (!$option) {
|
|
|
+ $option = Dever::issets($this->config['struct'][$key], 'value');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isset($option)) {
|
|
|
+ if (is_string($option) && strpos($option, 'Dever') === 0) {
|
|
|
+ eval('$option=' . $option . ';');
|
|
|
+ } elseif (is_string($option)) {
|
|
|
+ $option = Dever::db($option)->select([], ['col' => $col]);
|
|
|
+ } elseif (is_array($option) && !isset($option[0])) {
|
|
|
+ $temp = $option;
|
|
|
+ $option = array();
|
|
|
+ $col = explode(',', $col);
|
|
|
+ foreach ($temp as $k => $v) {
|
|
|
+ $option[] = array($col[0] => $k, $col[1] => $v);
|
|
|
}
|
|
|
- $this->config['struct'][$key]['option'] = $option;
|
|
|
}
|
|
|
if ($value && $option) {
|
|
|
if (is_array($value) && isset($value[$key])) {
|