Ejemplo n.º 1
0
 public function on_list()
 {
     $app = I("get.app");
     $schemas = SchemaService::getSchemaByApp($app);
     $this->response($schemas);
 }
Ejemplo n.º 2
0
 public static function data_format($data, $model, $is_table = false, $app = MODULE_NAME)
 {
     if (!$model && !$is_table) {
         return $data;
     }
     if (!$is_table) {
         $table = $model->getProperty('tableName') ? $model->getProperty('tableName') : array_shift(explode(' ', $model->getTableName()));
     } else {
         $table = $model;
     }
     $schemas = SchemaService::getSchemaByApp($app);
     $is_single = is_assoc($data);
     $schema = get_array_to_ka($schemas[$table]['structure'], 'field');
     // 单条数据
     if ($is_single) {
         $data = array($data);
     }
     foreach ($data as $k => $item) {
         foreach ($item as $field => $value) {
             if ($field === "id") {
                 $data[$k][$field] = (int) $value;
                 continue;
             }
             $is_exists = array_key_exists($field, $schema);
             // 数据表结构中包含字段
             if ($is_exists) {
                 $structure = $schema[$field];
                 $data[$k][$field] = self::data_field_format($value, $structure['type']);
             }
         }
     }
     return $is_single ? $data[0] : $data;
 }