/** * 基础表单 */ public static function baseFrom() { self::$table = strtolower(MODULE); self::$fieldPrefix = self::$table . "_"; self::$model = \Model\ModelManage::findModel(self::$table, 'model_name'); $field = \Model\Field::fieldList(self::$model['model_id'], array('field_status' => '1')); if (self::p('method') == 'PUT') { $data['noset'][self::$fieldPrefix . 'id'] = self::isP('id', '丢失模型ID'); if (!self::findContent(self::$table, $data['noset'][self::$fieldPrefix . 'id'], self::$fieldPrefix . 'id')) { self::error('不存在的模型'); } } foreach ($field as $value) { /** * 判断提交的字段是否为数组 */ if (is_array($_POST[$value['field_name']])) { $_POST[$value['field_name']] = (string) implode(',', $_POST[$value['field_name']]); } /** * 时间转换为时间戳 */ if ($value['field_type'] == 'date') { $_POST[$value['field_name']] = (string) strtotime($_POST[$value['field_name']]); } if ($value['field_required'] == '1') { if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name'])) && !is_numeric($data[self::$fieldPrefix . $value['field_name']])) { self::error($value['field_display_name'] . '为必填选项'); } } else { if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name']))) { $data[self::$fieldPrefix . $value['field_name']] = $value['field_default']; } } } return $data; }
/** * 基础表单 */ public static function baseFrom() { self::$table = strtolower(MODULE); self::$fieldPrefix = self::$table . "_"; self::$model = \Model\Model::findModel(self::$table, 'model_name'); $field = \Model\Field::fieldList(self::$model['model_id'], '1'); if (self::p('method') == 'PUT') { if (!($data['noset'][self::$fieldPrefix . 'id'] = self::isP('id'))) { return self::error($GLOBALS['_LANG']['MODEL']['LOST_MODEL_ID']); } if (!self::findContent(self::$table, $data['noset'][self::$fieldPrefix . 'id'], self::$fieldPrefix . 'id')) { return self::error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_MODEL']); } } foreach ($field as $value) { /** * 判断提交的字段是否为数组 */ if (is_array($_POST[$value['field_name']])) { $_POST[$value['field_name']] = (string) implode(',', $_POST[$value['field_name']]); } /** * 时间转换为时间戳 */ if ($value['field_type'] == 'date') { $_POST[$value['field_name']] = (string) strtotime($_POST[$value['field_name']]); } if ($value['field_required'] == '1') { if (!($data[self::$fieldPrefix . $value['field_name']] = self::isP($value['field_name'])) && !is_numeric($data[self::$fieldPrefix . $value['field_name']])) { return self::error($value['display_name'] . $GLOBALS['_LANG']['COMMON']['REQUIRED']); } } else { if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name']))) { $data[self::$fieldPrefix . $value['field_name']] = $value['field_default']; } } } return self::success($data); }