【问题标题】:Zf2 ScnSocialAuth HybridAuth zfcuser and RoutesZf2 ScnSocialAuth HybridAuth zfcuser 和路由
【发布时间】:2015-07-08 01:27:41
【问题描述】:

使用 ZF2 自定义基于 ZfcUser 的 Entity。尝试使用 ScnSocialAuth 并遇到了一些问题。 问题是我正在使用自定义路由('/account' 而不是'/user'),并且在实施 ScnSocialAuth 时,我无法将社交代码放入我的自定义 zfcuser 视图中......? 我有 \\view\zfc-user\user\register.php 覆盖 zfcuser 注册。 我有一条自定义路线:

'account' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                        'route' => '/account',
                ),
        ),

这些是我在 \my-module\config\module.config.php 中的 zfc 配置修改

    'zfcuser' => array(
        // telling ZfcUser to use our own class
        'user_entity_class'       => 'WMember\Entity\WMember',
        // telling ZfcUserDoctrineORM to skip the entities it defines
        'enable_default_entities' => false,
        'table_name' => 'w_member',
        'login_redirect_route' => 'account',
),

我的全局\config\application.config.php

'ScnSocialAuth',
'MyModule1',
'ZfcBase',
'ZfcUser',
'BjyAuthorize',
'GoalioMailService',
'GoalioForgotPassword',
'my-user-module',

因此,毕竟:

  1. 我可以通过导航到我自己的扩展用户注册表单 /account/register 没有可见的社交登录链接
  2. 导航到 /user/register 时我可以看到 ScnSocialAuth

a) 我无法在我的模块中创建视图来覆盖 \vendor\scn-social-auth\user\register.phtml,就像使用 zfcuser 所做的那样

请帮助让 ScnSocialAuth 与我的自定义路由设置一起使用。 如果这是错误的,请告诉我,因为我不是 ZF2 专家。乐于接受“建设性”的批评。

看到这些帖子:How to (correctly) extend ScnSocialAuth\Authentication\Adapter\HybridAuth::authenticate() method? 这是上述帖子的结果: https://github.com/SocalNick/ScnSocialAuth/issues/202

注意:由于 PHP 5.3,5.4,仍在运行 ZF-2.3*

【问题讨论】:

  • 注意:我可以使用 ['template_map']['zfc-user/user/register'] => DIR 路径显式覆盖视图文件。完成此操作后,我会收到“致命错误:调用成员函数 getEnabledProviders()”,并且此视图助手似乎不可用? $this->options->getEnabledProviders()

标签: zend-framework2 zfcuser


【解决方案1】:

您需要覆盖zfcuser 路由,而不是向您的配置添加自定义路由

<?php
// @file MyUserModule/config/module.config.php
return array(
    // other config ...

    'router' => array(
         'routes' => array(
            'zfcuser' => array(
                'options' => array(
                    // this is the only change needed to route zfcuser to /account
                    'route' => '/account',
                ),
            ),
         ),
     ),

     // more config ...
);

ScnSocialAuth 模块使用 forward() 插件来呈现来自 zfcusers 注册视图(和登录视图 iirc)的内容,这意味着它只会查看 zfcuser 路由并完全忽略您的自定义路由。让它使用您的自定义路由的唯一方法是使用相同的代码用您自己的替换 ScnSocialAuths UserController 但转发到您的自定义路由(那里还有更多工作,并且仍然有可能破坏任何其他期望 zfcuser 成为使用的路线)

【讨论】:

  • 感谢 Crisp 的快速回复。不幸的是,我的@file MyUserModule/config/module.config.php 配置数组中已经有了这个。 ' 'router' => array( 'routes' => array( // 开始覆盖zfcuser的路由 'zfcuser' => array( // 'type' => 'Zend\Mvc\Router\Http\Literal', 'options ' => array( 'route' => '/account', ), ), ' 从配置中删除“literal”之后,这个解决方案似乎仍然需要回退到 'user' 路由而不是 'account'
  • 看起来模块开发人员的回答让我更接近:覆盖 scn-social-auth-user 的配置键,并将“路由”设置为您尝试访问的自定义路由。这与上面提到的 zfcuser 调整一起似乎到达了那里。现在我在 zfcuser 注册方面遇到了另一个问题,即使在删除 scn-social 模块时我现在也无法注册(无法执行语句(42S22 - 1054 - '字段列表'中的未知列'array_copy'))......另一个错误解决...
猜你喜欢
  • 2015-10-14
  • 1970-01-01
  • 1970-01-01
  • 2015-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-20
相关资源
最近更新 更多