2013-05-16 3 views
0

폼의 레이블 위치를 변경하는 방법이 있습니까? 나는 입력 필드 (sfWidgetFormInputText 및 sfWidgetFormChoice) 위에 그것을 갖고 싶습니다. 그게 가능하니?Symfony 1.4 폼의 레이블 위치

답변

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

당신은 당신이 (... <td><th>, <tr>) html 태그를 사용하는 모든 양식을 재구성 할 수있는 형태와 관련된 template에 그것을 할 수 있습니다.