2013-05-16 52 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