独立的Twig表单和自定义MVC模式

just a pretty simple question regarding Twig standalone templating system, I have it installed as a package with my private project which is a php MVC, as it goes i am pleased with Twig, however when it comes to Forms im a little confused by it.

Basically Google after Google seems to return the same thing that it requires the Symfony Forms package to render the forms, however on the Twig website there is barely a mention of Symfony and to be honest it does seem to point that it is indeed a standalone package.

Now the issue is that i can render any form i like using plain html but as soon as i use any kind of Twig syntax to build the form then it just throws out Twig error after Twig error and obviously kills any rendering stone dead.

So i installed the Symfony forms package and to be honest it just seems to fly in the face of what would be acceptable MVC pattern and apart from that its just downright confusing and seems to be overkill.

Has anyone any experience in what i am saying regarding the Twig form syntax as standalone and actually get it to work or is plain html inside the Twig template the only option?.

thanks.

OK, well after sometime messing around with standalone symfony forms to render forms in Twig templating system and not really getting anywhere fast i decided that for my project which is just a personal project where i am taking my first real steps into OOP and proper (however that can be defined for a web application) MVC principles i decided to ditch Symfony standalone component and build up my own form builder class from scratch.

My form builder class covers allsorts of eventualities should i need them and is kept in a Helpers directory, i call it from a seperate controller class (Registration for example) and process data via a Registration Model.

Im actually quite pleased at how it turned out, it is simpler for me to use than Symfony and Twig handles it perfectly, i just need to set up some error handling and XSS protection etc and its good to go.

Many thanks to the contributers, right now Symfony seemed a little too intense for my needs which doesn't mean to say i wont be getting some practice at it at some point later as my skill set develops.

Yes, you can use Twig without Symfony, there is nothing magic in it. You should just include Twig autoloader file and use Twig. An example from my project:

include `Twig/Autoloader.php`

//init Twig environment
$loader = new \Twig_Loader_Array($dbAdapter->getTwigNotificationTemplates());
$twig = new \Twig_Environment($loader);
$this->template = $twig->loadTemplate('YourTemplateName');

BTW this qusetion was asked already on SO, but nice answer there wasn't marked as The Answer. It is here: Twig using without Symfony