Symfony PUGX Bundle - 传递自定义变量

时间:2014-12-25 17:07:45

标签: symfony fosuserbundle pugxmultiuserbundle

我使用PUGX Bundle来管理我的用户。

我想简单地传递给注册模板,一些自定义变量,但我不知道怎么做!

这里是控制器的代码:

/**
* @Route("/register", name="company_registration")
*/
public function registrationCompanyAction(Request $request)
{

     return $this->container
        ->get('pugx_multi_user.registration_manager')
        ->register('AppBundle\Entity\Company');
}

我该怎么办?

谢谢!

1 个答案:

答案 0 :(得分:2)

如果自定义变量是以config.yml中显示的表单类型定义的,则可以在模板中呈现,例如,

config.yml

...
pugx_multi_user:
  users:
    staff:
        entity: 
          class: Truckee\MatchingBundle\Entity\Staff
#          factory: 
        registration:
          form: 
            type: Truckee\UserBundle\Form\StaffFormType
            name: staff_registration
            validation_groups:  [Registration, Default]
          template: TruckeeUserBundle:Staff:staff.form.html.twig

表单类型

class StaffFormType extends BaseType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);

        $builder
                ->add('organization', new OrganizationType())
        ;
    }

    public function getName()
    {
        return 'staff_registration';
    }
...
}

员工表格模板

{% block content %}
    <h4 onclick="orghelp();" title="Click for help">{{label_info('Staff Registration Form <span class="glyphicon glyphicon-question-sign"></span>') }}</h4>
    <div id="dialog"><style>.ui-dialog-titlebar-close {
                display: none;
            }</style></div>    
            {% block fos_user_content %}
                {% include 'TruckeeUserBundle:Staff:staff_content.html.twig' %}
            {% endblock fos_user_content %}
        {% endblock %}

内容模板

{% trans_default_domain 'FOSUserBundle' %}

<form action="{{ path('staff_registration') }}" method="POST" class="form-inline">
    {%if form._token is defined %}{{ form_widget(form._token) }}{% endif %}
    {{ bootstrap_set_style('form-inline') }}
    {% include "TruckeeUserBundle:Person:person_manage.html.twig" %}
    <p><strong>Organization</strong></p>
    <div id="orgNotice"></div>
    {% set staff = form %}
    {% set form = form.organization %}
    <div id="orgForm">
        {% include "TruckeeMatchingBundle:Organization:orgForm.html.twig" %}
        <div>
            {{ bootstrap_set_style('') }}
            {% set form = staff %}
            {{ form_widget(form.save) }}
        </div>
    </div>
</form>