0

在不断努力将多用户捆绑包合并到一个项目中时,我得到了

在第 3 行的 FOSUserBundle:Registration:register_content.html.twig 中呈现模板期间引发了异常(“无法为命名路由“fos_user_registration_register”生成 URL,因为此类路由不存在。”)。

我已经多次阅读文档,但还没有看到在以下配置中我犯了错误。当我在 dev 中转到 /register/staff 时,会发生上述错误。无法弄清楚我们如何获得原始 fos 注册。

编辑:下面附加的堆栈跟踪,显示到 FOSUserBundle 的转换

配置.yml

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: Vol\VolBundle\Entity\Person
#    registration:
#        form:
#            type: vol_user_registration
    service:
        user_manager: pugx_user_manager

pugx_multi_user:
  users:
    staff:
        entity: 
          class: Vol\VolBundle\Entity\Staff
#          factory: 
        registration:
          form: 
            type: Vol\VolBundle\Form\RegistrationStaffFormType
            name: fos_user_registration_form
            validation_groups:  [Registration, Default]
          template: VolVolBundle:Registration:staff.form.html.twig
        profile:
          form:
            type: Vol\VolBundle\Form\ProfileStaffFormType
            name: fos_user_profile_form
            validation_groups:  [Profile, Default] 
    volunteer:
        entity: 
          class: Vol\VolBundle\Entity\Volunteer
        registration:
          form: 
            type: Vol\VolBundle\Form\RegistrationVolunteerFormType
          template: VolVolBundle:Registration:volunteer.form.html.twig
        profile:
          form: 
            type: Vol\VolBundle\Form\ProfileVolunteerFormType

路由.yml:

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

#rem'd for PUGX multi-user bundle
#fos_user_register:
#    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
#    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

##add following for PUGX multi-user bundle
staff_registration:
    pattern:  /register/staff
    defaults: { _controller: VolVolBundle:RegistrationStaff:register }

volunteer_registration:
    pattern:  /register/volunteer
    defaults: { _controller: VolVolBundle:RegistrationVolunteer:register }

控制器:

class RegistrationStaffController extends Controller
{
    /**
     * @return type
     */
    public function registerAction()
    {
        return $this->container
                    ->get('pugx_multi_user.registration_manager')
                    ->register('Vol\VolBundle\Entity\Staff');
    }
}

根据要求,模板 staff.form.html.twig 和 staff_register_content.html.twig:

//staff.form.html.twig
{% extends 'VolVolBundle:Default:layout.html.twig' %}
{% block body %}
Staff Registration Form
{% block fos_user_content %}
{% include 'VolVolBundle:Registration:staff_register_content.html.twig' %}
{% endblock fos_user_content %}
{% endblock %}

//staff_register_content.html.twig
{% trans_default_domain 'FOSUserBundle' %}

<form action="{{ path('staff_registration') }}" {{ form_enctype(form) }} method="POST">
    {{ form_widget(form) }}
    <div>
        <input type="submit" value="{{ 'registration.submit'|trans }}" />
    </div>
</form>

默认布局:

<!DOCTYPE html >
<head>
{% stylesheets '@VolVolBundle/Resources/public/css/*' filter='cssrewrite' %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}</head>
<body class="background" >
        {% block body %}

        {% endblock %}
</body>

堆栈跟踪

at Symfony\Bundle\TwigBundle\TwigEngine->renderResponse('FOSUserBundle:Registration:register.html.twig', array('form' => object(FormView)))
    in G:\Documents\workspace\volunteer\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Controller\RegistrationController.php line 78

at FOS\UserBundle\Controller\RegistrationController->registerAction(object(Request))
    in G:\Documents\workspace\volunteer\vendor\pugx\multi-user-bundle\PUGX\MultiUserBundle\Controller\RegistrationManager.php line 63

at PUGX\MultiUserBundle\Controller\RegistrationManager->register('Vol\VolBundle\Entity\Staff')
    in G:\Documents\workspace\volunteer\src\Vol\VolBundle\Controller\RegistrationStaffController.php line 25

at Vol\VolBundle\Controller\RegistrationStaffController->registerAction()
    in  line 

at call_user_func_array(array(object(RegistrationStaffController), 'registerAction'), array())
    in G:\Documents\workspace\volunteer\app\bootstrap.php.cache line 2911

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
    in G:\Documents\workspace\volunteer\app\bootstrap.php.cache line 2883

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
    in G:\Documents\workspace\volunteer\app\bootstrap.php.cache line 3022

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
    in G:\Documents\workspace\volunteer\app\bootstrap.php.cache line 2303

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
    in G:\Documents\workspace\volunteer\web\app_dev.php line 28
4

3 回答 3

1

对捆绑包说明的误解。修改后的 routing.yml,其中 fos_user_register 没有被注释掉!

路由.yml

fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

##add following for PUGX multi-user bundle
staff_registration:
    pattern:  /register/staff
    defaults: { _controller: VolVolBundle:RegistrationStaff:register }

volunteer_registration:
    pattern:  /register/volunteer
    defaults: { _controller: VolVolBundle:RegistrationVolunteer:register }
于 2014-02-19T22:35:12.580 回答
1

'VolVolBundle:Default:layout.html.twig' 是否包含注册链接?

fos_user_registration_registerroute 在您的一个模板中的某个地方被调用。

于 2014-02-19T08:38:52.417 回答
0

看了上面的内容,我猜你的里面VolVolBundle:Default:layout.html.twig没有{% block body %}块?

如果VolVolBundle:Default:layout.html.twigFOSUserBunde::layout.html.twig模板的副本,则不会,这意味着您{% block fos_user_content %}很可能不会覆盖布局模板并且(不知何故)正在使用 FOSUserBundle 默认值。

您也可以发布您的VolVolBundle:Default:layout.html.twig模板吗?

于 2014-02-19T09:50:50.453 回答