function _replaceValue(&$mVal, $data) { if (is_array($mVal)) { foreach ($mVal as &$val) { _replaceValue($val, $data); } } else { preg_match_all("/\\{\\w+\\}/", $mVal, $matches); foreach ($matches[0] as $value) { $key = str_replace(array('{', '}'), '', $value); $mVal = str_replace($value, $data[$key], $mVal); } } }
protected function replaceValue(&$aValue, $data) { foreach ($aValue as $key => &$mVal) { if ($key > 1) { _replaceValue($mVal, $data); } } }
protected function getHref($href, $aValue, $vars) { if (substr($href, 0, 7) == '__URL__') { $urlbase = __URL__; $href = substr($href, 7); } else { $urlbase = __APP__; } _replaceValue($href, $aValue); _replaceValue($href, $vars, '[', ']'); return $urlbase . $href; }
function _replaceValue(&$mVal, $data, $tag_begin = '{', $tag_end = '}') { if (is_array($mVal)) { foreach ($mVal as &$val) { _replaceValue($val, $data); } } else { preg_match_all("/\\" . $tag_begin . "\\w+\\" . $tag_end . "/", $mVal, $matches); foreach ($matches[0] as $value) { $key = str_replace(array($tag_begin, $tag_end), '', $value); $mVal = str_replace($value, $data[$key], $mVal); } } }
protected function getOperationHtml($config, $aValue, $field, $vars) { $s = ''; if (is_array($config[1])) { foreach ($config[1] as $operate) { $s .= ' '; switch ($operate) { case 'edit': $s .= '<a href="' . __URL__ . '/edit/id/' . $aValue['id'] . '">编辑</a>'; break; case 'delete': $s .= '<a href="' . __URL__ . '/delete/id/' . $aValue['id'] . '" onclick="if(!confirm(\'确定删除该记录?\')){return false;}">删除</a>'; break; case 'picture': $s .= '<a href="' . __URL__ . '/picture/id/' . $aValue['id'] . '">图库</a>'; break; case 'img': $s .= '<img src="' . $aValue[$field] . '" width="80" height="80" />'; break; default: if (is_array($operate)) { //处理链接地址 if (substr($operate[0], 0, 7) == '__URL__') { $urlbase = __URL__; $operate[0] = substr($operate[0], 7); } else { $urlbase = __GROUP__; } _replaceValue($operate[0], $aValue); _replaceValue($operate[0], $vars, '[', ']'); $href = $urlbase . $operate[0]; //提示确认信息 $confirm = ''; if (isset($operate[2]['confirm'])) { $confirm = ' onclick="if(!confirm(\'' . $operate[2]['confirm'] . '\')){return false;}"'; } //选中状态判断 $checked = false; if (isset($operate[2]['checked'])) { $expression = $operate[2]['checked']; _replaceValue($expression, $aValue); _replaceValue($expression, $vars, '[', ']'); //echo "\$checked = ($expression);"; eval("\$checked = ({$expression});"); } if ($checked) { $s .= $operate[1]; } else { $s .= '<a' . $confirm . ' href="' . $href . '">' . $operate[1] . '</a>'; } } else { //非数组则输出原始字符串 $s .= $operate; } break; } $s .= ' '; } } return $s; }