Symfony2 standalone form component - setting up a form
I'm trying to implement Symfony2 form builder component as a standalone. The documentation doesn't really talk about this though, just in relation to using the whole framework.
The standalone is on Github but has no docs.
Ive searched around and seen a few people ask this ques开发者_运维技巧tion but none seems to have any answers.
All I need is a basic guide on how to setup a form , build it, then view it.
Anyone?
Edit: My first response below is now obsolete (and the link does not work anymore). Please refer to https://github.com/webmozart/standalone-forms for a state-of-the-art solution.
Previous (now obsolete) answer:
I've tried hard and managed to display a form (using PHP engine, not Twig).
Indeed you need a few components: Form, but also ClassLoader, EventDispatcher, Templating (for rendering) and Translation (for rendering labels). You will also need some resources from the FrameworkBundle bundle (mainly templates).
More info on this: http://forum.symfony-project.org/viewtopic.php?f=23&t=36412
And my mini-tutorial: http://n.clavaud.free.fr/blog/index.php?article31/symfony2-standalone-form-component-tutorial
First, copy Form Component to your project to directory which contains third-party libraries (not only Symfony components, but also ORM or whatever), let's say lib/
, so it's in <project_path>/lib/Symfony/Component/Forms
.
Then you have to auoload it - either manually or using any PSR-0 compatible class loader i.e. SplClassLoader or Symfony's UniversalClassLoader (there is chapter in docs and in quick tour about this). Example:
$loader = new UniversalClassLoader();
$loader->registerNamespace('Symfony', __DIR__.'/lib');
$loader->register();
Using Form Component isn't in fact strongly documented, but in Symfony Book there are few examples how to use Form classes about this component, so I guess you'll have to dive into sources, beginning with Form class (maybe later you'll give some feedback about experiences somewhere in the Web?).
Since Symfony 2.1, the form component has been using composer.
You can locate the composer.json file inside the repository. It contains a dependency map that can be used to get the dependencies installed.
You can do so by simply running composer install
from inside your console.
P.S I know this thread is old. The information I'm contributing apply to any new users that may need it.
First of all not with Symfony2. But creating form with Aura.Input and some view helpers of Aura.View makes it easy to bring Standalone Forms and Validation.
If you are interested you can read it over http://harikt.com/phpform/ , and source is in github.
/* * This file is part of the Symfony package.....
what i understand from that line is that the file is a PART of the framework, can't be removed, can't be ripped, and it won't function if you rip it off the package because it requires other related files in the framework
however, there is an option, and it is to investigate the files and see what functions they call and what variables they use ,redefine them, and use it as standalone IF the license allows you to
精彩评论