/** * 自动表单处理 * @access public * @param array $data 创建数据 * @param string $type 创建类型 * @return mixed */ private function autoOperation(&$data, $type) { if (!empty($this->options['auto'])) { //自动完成静态和动态结合 if (!empty($this->_auto)) { $_auto = array_merge($this->_auto, $this->options['auto']); } else { $_auto = $this->options['auto']; } //$_auto = $this->options['auto']; unset($this->options['auto']); } elseif (!empty($this->_auto)) { $_auto = $this->_auto; } // 自动填充 if (isset($_auto)) { foreach ($_auto as $auto) { // 填充因子定义格式 // array('field','填充内容','填充条件','附加规则',[额外参数]) if (empty($auto[2])) { $auto[2] = self::MODEL_INSERT; } // 默认为新增的时候自动填充 if ($type == $auto[2] || $auto[2] == self::MODEL_BOTH) { if (empty($auto[3])) { $auto[3] = 'string'; } switch (trim($auto[3])) { //todo 增加api调取方式 case 'api': case 'function': // 使用函数进行填充 字段的值作为参数 // 使用函数进行填充 字段的值作为参数 case 'callback': // 使用回调方法 $args = isset($auto[4]) ? (array) $auto[4] : array(); if (isset($data[$auto[0]])) { array_unshift($args, $data[$auto[0]]); } if ('api' == $auto[3]) { $data[$auto[0]] = API($auto[1], array($args)); } else { if ('function' == $auto[3]) { $data[$auto[0]] = call_user_func_array($auto[1], $args); } else { $data[$auto[0]] = call_user_func_array(array(&$this, $auto[1]), $args); } } break; case 'field': // 用其它字段的值进行填充 $data[$auto[0]] = $data[$auto[1]]; break; case 'ignore': // 为空忽略 if ($auto[1] === $data[$auto[0]]) { unset($data[$auto[0]]); } break; case 'string': default: // 默认作为字符串填充 $data[$auto[0]] = $auto[1]; } if (isset($data[$auto[0]]) && false === $data[$auto[0]]) { unset($data[$auto[0]]); } } } } return $data; }
function displayMain($interest) { API($interest); }
} // Confirm KEY $matches = (array) json_decode($_POST['matches']); foreach ($matches as $match) { $match = (array) $match; var_dump($match); var_dump($match['red a']); $db->bind("match_num", $match['match number']); $db->bind("rA", $match['red a']); $db->bind("rB", $match['red b']); $db->bind("bA", $match['blue a']); $db->bind("bB", $match['blue b']); $db->getAll("CALL addMatch(:match_num, :rA, :rB, :bA, :bB)"); $db->bind("match_num", $match['match number']); $db->bind("rScore", $match['red score']); $db->bind("bScore", $match['blue score']); $db->getAll("CALL updateMatchScore(:rScore, :bScore, :match_num)"); } return array("status" => 1); } else { if ($mode == "getMatches") { $res = $db->getAll("SELECT * FROM matches"); return array("status" => 1, "result" => $res); } } } } } $db = new DB(); $result = API($db, $_GET); echo json_encode($result);