2013-05-16 50 views

回答

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

感谢您的帮助!我创建了一个新的格式化类,它可以按我的意愿工作。 – alex

0

你必须这样做,在其中您可以重新组织使用HTML标签的所有形式(<th><tr><td> ....)的形式相关的template