This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Symfony tutorial for using standalone components

About symfony tutorials, symfony book and API documentation.

Symfony tutorial for using standalone components

by VelvetMirror » Fri May 06, 2011 9:10 am

The support for Symfony 1.4 in hostings must be trough a VPS (Virtual Private Server) or a dedicated server, because you have to change the apache configuration that can mess up other sites in the hosting (that's what I've been told at least).

So if you are on a normal shared hosting you can't use Symfony 1.4, but you can still use the standalone components like sfForms.

Also for example if you already have an existent web aplication and you don't want to change it all in order to use Symfony, it would be useful to be able to use the components separately.

Here you can read a little explanation about how it's possible to use standalone components without Symfony: ... rine/en/11

But it's only an overview and doesn't actually explain how to do it, it would be nice if someone could write a tutorial with an example implementation.

Here is some code I've adapted in order to try to use the sfForm component, to make it work you must copy the symfony folder inside lib/vendor/ on your project.

This would be the bootstrap.php:

Code: Select all
$symfony_path = '\lib\vendor\symfony-1.4.11\lib'; // Change this to match your configuration.
require_once $symfony_path . '\autoload\sfCoreAutoload.class.php';

This would be the index.php:

Code: Select all

class ExampleForm extends sfForm {

    public function configure() {
            'example_text' => new sfWidgetFormInput()

            'example_text' => new sfValidatorString(array('max_length' => 2, 'required' => true))

            'example_text' => 'Example Text'

        // I had to specify this, there wasn't any formatting by default.

        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);


$form = new ExampleForm(array(
            'example_text' => 'Default Value'

if (!empty($_POST)) {

    if ($form->isValid()) {
<h1>Example Form</h1>
<form action="test.php" method="post">
        <?php echo $form ?>
                <input type="submit" value="Submit" />

Because I'm new to Symfony I'm aware that this may be not a good example, so if someone more experienced could write a little tutorial explaining this, it would be really nice.
User avatar
Senior Member
Posts: 123
Joined: Tue Apr 12, 2011 9:53 am