Zend Expressive with Symfony form and Twig view helpers

Hello all,

I’m trying an application with Zend Expressive but I am used to work with Symfony. So I wanted to work with Symfony Form and Twig view helpers (like form_start, form_end…).

First I install symfony/form, I can create form. It is a bit more complicated than in Symfony but finaly I can create Form.

In my Twig view, I want to use form_start, form_row… It doesn’t work… So I’ve search and install symfony/twig-bridge. I’ave added a little config
‘dependencies’ => [
‘factories’ => [
TwigExtension::class => FormExtension::class,
]
]
then
class FormExtension
{
public function __invoke() : \Twig_Extension
{
$formExtension = new \Symfony\Bridge\Twig\Extension\FormExtension();
return $formExtension;
}
}

but it ends with an error :

 Twig_Error_Runtime

Unable to load the “Symfony\Component\Form\FormRenderer” runtime.

So now, I don’t really know if it was really a good idea…

I really like Expressive but it seems not so simple to use others libs than Zend.

Does somebody know how to achieve my problem ?

The problem is not at Zend expressive level. Some of the components are tightly bind to the framework. To use symfony I would recommend looking at https://github.com/webmozart/standalone-forms . You may want to make certain changes for Zend expressive don’t rely on symfony/request but psr-7 and integration of twig. I hope this will help. iirc there is also integration with slim by akrabat. You may want to search it.

I m not saying the problem comes from Zend expressive. I m saying it s not as easy as mentioned to use libs that doesn’t come from Zend. Your link talks about Symfony 2.7. The current is 4.3… I will have a look tomorrow anyway. Thanks.

The Twig\Environment need a RuntimeLoader for load Symfony\Component\Form\FormRenderer.

1 Like

Thanks I saw something like this in the code but I was affraid to get lots and lots dependencies, I will try to instanciate this RuntimeLoader and configure it. If it doesn’t work… I’ll give up :frowning:

This is my component of symfony/twig-bridge extension factories.

And this is example file

1 Like

Ohhhhh !!! I will try that ! right NOW ! :clap:

Thanks it seems to work. You need to promote your lib @Moln :wink: