贴一个自定义的 symfony 的表单皮肤 应用bootstrap效果

文章转自:http://blog.csdn.net/jiaochangyun/article/details/7245009#

效果如图

调用很方便

 

  1. {% import "JcyHelperBundle:tmp:jcyForm.html.twig" as forms %} 
  2. {{ forms.jcyForm(dbForm,path('JcyHelperBundle_db_set'),'Connect') }} 
{% import "JcyHelperBundle:tmp:jcyForm.html.twig" as forms %}
{{ forms.jcyForm(dbForm,path('JcyHelperBundle_db_set'),'Connect') }}

现在上源代码

  1. {% macro jcyForm(form,action,submit_name,onSubmitJs) %} 
  2. <formaction="{{ action }}"method="post"onsubmit="{{ onSubmitJs|default('') }}" {{ form_enctype(form) }}> 
  3. {% if form.vars.errors|length >0 %} 
  4. <divclass="alert alert-error"> 
  5. {% for error in form.vars.errors %} 
  6. {% if loop.index>1 %}<br>{% endif %} 
  7. {{ error.messageTemplate|trans(error.messageParameters, 'validators') }} 
  8. {% endfor %} 
  9. </div> 
  10. {% endif %} 
  11. {% for key,v in form.children %} 
  12. {% if key != '_token' %} 
  13. <divclass="control-group{% if v.vars.errors|length >0 %} error{% endif %}"> 
  14.     <divclass="input-prepend"> 
  15.     <labelclass="control-label add-on"style="width:60px;text-align:right"for="{{v.vars.id}}">{{v.vars.label}} :</label> 
  16.         <divclass="controls"> 
  17.             {{ form_widget(v) }} 
  18.             <spanclass="help-inline"> 
  19.             {% if v.vars.errors|length >0 %} 
  20.             {% for error in v.vars.errors %} 
  21.             {% if loop.index>1 %},{% endif %} 
  22.             {{ error.messageTemplate|trans(error.messageParameters, 'validators') }} 
  23.             {% endfor %} 
  24.             {% endif %} 
  25.             </span> 
  26.         </div> 
  27.     </div> 
  28. </div> 
  29. {% endif %} 
  30. {% endfor %} 
  31. {{ form_rest(form) }} 
  32. <inputtype=submitid="submit_btn"class="btn-primary span2"value="{{ submit_name }}"> 
  33. </form> 
  34. {% endmacro %} 
posted @ 2013-01-29 10:46  V.Wang  阅读(382)  评论(0编辑  收藏  举报