dourong4031 2016-11-24 14:57
浏览 62
已采纳

独立的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.

  • 写回答

2条回答 默认 最新

  • doujiaohuo1096 2016-12-06 13:35
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现