kingsquare/json-schema-form 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kingsquare/json-schema-form

最新稳定版本:0.6

Composer 安装命令:

composer require kingsquare/json-schema-form

包简介

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

README 文档

README

Generate forms based on JSON Schema

A framework-agnostic PHP Implementation for generating simple forms based on json-schema . This package is compatible with version 4 and may be combined with

Installation

Library

$ wget http://getcomposer.org/composer.phar
$ php composer.phar install --save kingsquare/json-schema-forms

Usage

<?php

// Get the schema and data as objects
$retriever = new JsonSchema\Uri\UriRetriever;
$schema = $retriever->retrieve('file://' . realpath('schema.json'));

// Generate
$formGenerator = new JsonSchemaForm\Generator($schema);
echo $formGenerator->render();
?>

See examples folder for a few more options.

Extra styling and JavaScript is required for proper presentation and validation.

Process form data

To validate any data in the form against the schema, the form data should be casted to the proper datatypes. Validation of form data may look like

<?php
$validator = new JsonSchema\Validator();
$dataParser = new JsonSchemaForm\DataParser();

//cast any posted form-data (strings) to the proper data-types
$data = $dataParser->parse($_POST['root'], $schema);

$validator->check($data, $this->schema);

$message = "The supplied JSON validates against the schema.\n";
if (!$validator->isValid()) {
	$message = "JSON does not validate. Violations:\n";
	foreach ($validator->getErrors() as $error) {
		$message .= print_r($error, true);
	}
}
echo $message;

Running the tests

$ phpunit

统计信息

  • 总下载量: 8.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 30
  • Watchers: 7
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-07-09