万迪 / ordered-form
为Symfony2表单组件提供表单排序支持。
3.0.2
2020-03-20 09:34 UTC
Requires
- php: ^5.6|^7.0
- symfony/form: ^2.7|^3.0|^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- phpunit/phpunit: ^5.0
- symfony/phpunit-bridge: ^2.7|^3.0|^4.0|^5.0
README
该库允许您通过添加位置选项来按顺序排列您的Symfony2表单字段。位置可以是第一个、最后一个或一个描述在某个字段之前或之后的关联数组。
万迪笔记
注意:这是一个Symfony 4分支
如果您想使用此Bundle与Symfony框架标准版一起使用,并在扩展Symfony\Bundle\FrameworkBundle\Controller\AbstractController
的Controller
中使用CreateForm
方法,请按照以下快速指南操作
// config/services.yaml Symfony\Component\Form\FormExtensionInterface: "@form.extension"
之前(经典案例)
namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class YourController extends AbstractController { // [...] public function __construct(/* DI */) { // [...] } public function yourAction(Request $request): Response { $yourEntity = new Entity(); $form = $this->createForm(YourType::class, $yourEntity, [ // your options ]); $form->handleRequest($request); // [...] } }
之后
namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Form\FormExtensionInterface; use Ivory\OrderedForm\Extension\OrderedExtension; use Symfony\Component\Form\Forms; use Ivory\OrderedForm\OrderedResolvedFormTypeFactory; class YourController extends AbstractController { /** * @var FormExtensionInterface */ private $formExtension; public function __construct(FormExtensionInterface $formExtension) { $this->formExtension = $formExtension; } public function yourAction(Request $request): Response { $yourEntity = new Entity(); $formFactory = Forms::createFormFactoryBuilder() ->setResolvedTypeFactory(new OrderedResolvedFormTypeFactory()) ->addExtension($this->formExtension) ->addExtension(new OrderedExtension()) ->getFormFactory(); $form = $formFactory->create(YourType::class, $yourEntity, [ // your options ]); $form->handleRequest($request); // [...] } }
文档
测试
该库通过PHPUnit进行全面的单元测试,代码覆盖率接近100%。要执行测试套件,请检查travis的配置文件。
贡献
我们热爱贡献者!Ivory是一个开源项目。如果您想贡献,请随时提出PR!您可以查看CONTRIBUTING文件,其中将解释如何设置项目。
许可
Ivory Ordered Form采用MIT许可。有关完整的版权和许可信息,请阅读随源代码一起分发的LICENSE文件。