有没有办法改变表单中标签的位置?我想要它在输入字段上方(sfWidgetFormInputText和sfWidgetFormChoice)。那可能吗?Symfony 1.4表单中的标签位置
0
A
回答
2
取决于您如何渲染表单域。你能做到几个方面:
如果你想以不同的方式呈现单个字段在表单中的其余部分,可以使标签和模板单独窗口小部件是这样的:
// \apps\myApp\modules\myModule\templates\_form.php
echo $form['field_name']->renderLabel(); // Render the label
echo $form['field_name']->render(); // Render the widget
echo $form['field_name']->renderError(); // Render the error
echo $form['field_name']->renderHelp(); // Render the help message
如果你想要在整个表单上应用布局。您应该创建一个新的格式化程序类,并将其应用到您的窗体:
// \lib\form\formatter\sfWidgetFormSchemaFormatterCustom.class.php
class sfWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = '<div class="label">%label%</div><div class="field">%field%</div>%error% \n %help %hidden_fields%',
$errorRowFormat = '<div>%errors%</div>',
$helpFormat = '<div class="form_help">%help%</div>',
$decoratorFormat = '<div>\n %content%</div>';
}
应用在你的窗体的配置方法是这样的:
// \lib\form\myForm.class.php
public function configure()
{
//....
$formatter = new sfWidgetFormSchemaFormatterCustom($this->getWidgetSchema());
$this->widgetSchema->addFormFormatter('custom', $formatter);
$this->widgetSchema->setFormFormatterName('custom');
}
如果要跨项目在全球范围使用的格式,您可以将它设置为ProjectConfiguration.class.php中的默认格式化程序。
// \config\ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// ...
sfWidgetFormSchema::setDefaultFormFormatterName('custom');
}
}
0
你必须这样做,在其中您可以重新组织使用HTML标签的所有形式(<th>
,<tr>
,<td>
....)的形式相关的template
。
相关问题
- 1. Symfony 1.4中的动态表单域
- 2. symfony 1.4中的多级嵌入表单
- 3. Sonata和Symfony 2中的表单标签
- 4. 在教条配置中配置symfony表单标签
- 5. Symfony的表单标签翻译错误
- 6. 表单标签上的Id属性symfony
- 7. 如何更改symfony 1.4中的过滤器标签?
- 8. 配置在factories.yml中symfony的1.4
- 9. symfony 1.4中的SSL安装配置
- 10. Symfony 2 - 表单集合 - 标签翻译
- 11. Symfony表单复选框标签翻译
- 12. 为什么HTML标签在Symfony 1.4中不能正确渲染?
- 13. 定位表单标签
- 14. 定制“所需”的Symfony 1.4(动态标签)的错误
- 15. Symfony 2或Symfony 1.4?
- 16. TextButton中的位置标签?
- 17. 使用Symfony 1.4 sfGuardUser表和Symfony 2 SecurityBundle?
- 18. Symfony 1.4教条创建表
- 19. Symfony 1.4自定义表格
- 20. Symfony 1.4嵌入表格
- 21. 如何在symfony 1.4中配置任务?
- 22. 在Symfony 1.4中重置用户密码
- 23. Zend框架中的表单字段和标签位置2
- 24. 标签的位置
- 25. 构建表单时,哪里是设置标签值的最佳位置?
- 26. Symfony 1.4中保存的嵌入式表单的最大数量
- 27. 在symfony 1.4中使用symfony 2.0的角色1.4
- 28. symfony 1.4中的锁进程
- 29. Symfony 1.3或1.4中的sfLucene
- 30. 日志中的symfony 1.4 API
感谢您的帮助!我创建了一个新的格式化类,它可以按我的意愿工作。 – alex