fabpot/Silex — Issue #276: using sf2 form and validation classes
Author: Bieleke
Created: 2012-03-09 01:16:43+00:00
State: open

Hi Guys,

I use the folowing code...

// bootstrap the application
require_once __DIR__.'/../../app/bootstrap.php';

$app = new Silex\Application();

$app['debug'] = true;

if ($app['debug'] == true) {
error_reporting(E_ALL);
ini_set('display_errors', true);
// load the needed services
require_once __DIR__.'/../../app/services_dev.php';
} else {
// load the needed services
require_once __DIR__.'/../../app/services.php';
}

// we gonna use symfony form and validation classes
$app->register(new Silex\Provider\SymfonyBridgesServiceProvider(), array(
'symfony_bridges.class_path' => __DIR__.'/../../vendor/symfony/src',
));

$app->register(new Silex\Provider\FormServiceProvider(), array(
'form.class_path' => __DIR__ . '/../../vendor/symfony/src'
));

$app->register(new Silex\Provider\ValidatorServiceProvider(), array(
'validator.class_path' => __DIR__ . '/../../vendor/symfony/src',
));

// we also want to send an automatic mail to the member when the email is set
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
'swiftmailer.class_path' => __DIR__.'/../../vendor/swiftmailer/lib/classes',
));

//$app['session']->start();

use Symfony\Component\HttpFoundation\Request;

$app->get('/', function() use ($app) {

$form = $app['form.factory']->createBuilder('form')
->add('identifier', 'text')
->add('email', 'email')
->getForm() ;
return $app['twig']->render('helpdesk/test-silex.html.twig', array(
'public' => true, 'form' => $form->createView()
));

});

This produces the next error-code...

Catchable fatal error: Argument 1 passed to Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider::__construct() must be an instance of Symfony\Component\HttpFoundation\Session\Session, instance of Symfony\Component\HttpFoundation\Session given, called in phar:///var/www/vhosts/www.domain.com/private/vendor/Silex/silex.phar/src/Silex/Provider/FormServiceProvider.php on line 49 and defined in /var/www/vhosts/www.domain.com/private/vendor/symfony/src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/SessionCsrfProvider.php on line 41

My session is created in services.php like this...

$app->register(new Silex\Provider\SessionServiceProvider());
$app['session.storage.options'] = array('name' => 'giveitaname', 'lifetime' => 0, 'path' => '/', 'domain' => '.domain.com');

if i use...

$app->register(new Silex\Provider\SessionServiceProvider(), array(
'session.storage.options' => array('name' => 'giveitaname', 'lifetime' => 0, 'path' => '/', 'domain' => '.domain.com'),
));

it traps the same error.