Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 question 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?

like image 771
BobFlemming Avatar asked May 31 '11 11:05

BobFlemming


3 Answers

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

like image 195
Nicolas Clavaud Avatar answered Oct 14 '22 07:10

Nicolas Clavaud


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?).

like image 35
Xaerxess Avatar answered Oct 14 '22 09:10

Xaerxess


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.

like image 28
Nikola Petkanski Avatar answered Oct 14 '22 08:10

Nikola Petkanski