2010-02-11 72 views
2

是否有一種簡單的方法來爲Symfony表單標籤聲明CSS類?Symfony表單標籤的自定義CSS類?

這不起作用:

<?php echo $form['email']->renderLabel('class' => 'my-css') ?> 

發現這個和它的作品,但感覺與直覺相反的,因爲它使表單標籤本身已經過時,要求標籤在模板中寫出:

<?php echo $form['email']->renderLabel('This is a label text', array('class' => 'my-css') ?> 

任何人都知道更好的方法嗎?

感謝

+0

只是爲了搶先:是的,我知道這是可能的附加屬性在CSS,但我需要的迪菲這種特殊情況下只是「標籤」標籤租用同一種形式的標籤類型。 – Tom 2010-02-11 01:19:33

回答

2

您可以更改表單東北黑鈣土爲每個表單創建一個擴展sfWidgetFormSchemaFormatter定製類

class sfWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter 
{ 
    protected 
    $rowFormat  = "<tr>\n <th class=\"my-label-class\">%label%</th>\n <td>%error%%field%%help%%hidden_fields%</td>\n</tr>\n", 
    $errorRowFormat = "<tr><td class=\"my-error-class\" colspan=\"2\">\n%errors%</td></tr>\n", 
    $helpFormat  = '<br />%help%', 
    $decoratorFormat = "<table>\n %content%</table>"; 
} 

然後,您可以更改窗體類格式:

$this->getWidgetSchema()->setFormFormatterName('custom'); 

,或者您可以設置新的格式在config每個表單/ProjectConfiguration.class.php文件:

sfWidgetFormSchema::setDefaultFormFormatterName('custom');