_model ) $this->_model = new BaseDictDataModel(); } /** * 取得数据字典对应数据 * * @param string $table_code 数据字典的类型 * @param string $code 数据字典代码 * @param string $val 数据字典数据对应下标 * @return array 返回数据字典数组 * @throws CException $table_code, $code 不能为空 * */ public function get($table_code, $code, $val = null) { $mKey = Cache::get($this->_mmCache); if(isset($mKey[$table_code][$code])) { $arr = $mKey[$table_code][$code]; }else{ $this->updateCache(); if(isset($this->_dict[$table_code][$code])) { $arr = $this->_dict[$table_code][$code]; }else{ $arr = []; } } if(!$arr) { return null; } if(isset($val)) { if(array_key_exists($val, $arr)) { return $arr[$val]; }else{ return ''; } }else{ return $arr; } } /** * 创建Select代码 * * @param string $table_code 数据字典的类型 * @param string $code 数据字典代码 * @param string $selection 被选中的值。 * @param array $htmlOptions * 额外的HTML属性:如 [name=>'cate', id=>'cate'] 这些属性作用在select上。 * 若使用特定关键字empty时,自动创建一个option, * empty: 字符串,指定空选项的文本,它的值为空。 * empty: 数组,option的value值对应key,文本对应value。 */ public function select($table_code, $code, $selection = null, $htmlOptions = []) { $selectOption = $htmlOptions; unset($selectOption['empty']); $html = " $val) { $html .= " {$key}=\"{$val}\""; } $html .= ">\n"; if (isset ( $htmlOptions ['empty'] )) { $value = ""; $label = $htmlOptions ['empty']; if (is_array ( $label )) { $value = array_keys ( $label ); $value = $value [0]; $label = array_values ( $label ); $label = $label [0]; } $html .= "\n"; } $optionHtml = $this->option($table_code, $code, $selection); $html .= $optionHtml; $html .= ""; return $html; } /** * 创建select的option选项 * * @param $table_code * @param $code * @param null $selection * @return string */ public function option($table_code, $code, $selection = null) { $data = $this->get($table_code, $code); $html = ""; foreach ($data as $k => $v) { $html .= "