简体   繁体   English

在 Joomla 中成功注册后将用户重定向到自定义 URL

[英]Redirect user to custom URL after successful registration in Joomla

I want my users to redirect to a custom URL after they successfully register in Joomla .我希望我的用户在成功注册 Joomla 后重定向到自定义 URL。 I can't find any option for that !我找不到任何选择! How can I achieve this ?我怎样才能做到这一点?

If you are using Joomla!'s built-in menu to load the registration page, or getting there from the Login module there isn't a way to redirect (which is odd because you can set a redirect after login in the login module).如果您使用 Joomla! 的内置菜单来加载注册页面,或者从登录模块到达那里,则无法重定向(这很奇怪,因为您可以在登录模块中登录后设置重定向) .

The best place to start would be to look at existing solutions in the " Authentication " section of the Joomla!最好的起点是查看Joomla的“ 身份验证”部分中的现有解决方案! Extension Directory .扩展目录 It appears there are several listed that support both the old 1.5 style sites and the new 1.7/2.5 sites.似乎列出了几个既支持旧的 1.5 样式站点又支持新的 1.7/2.5 站点的列表。

(By the way if you are still on 1.7 you should update to the latest 2.5 as there are serious security issues in the 1.7 line.) (顺便说一句,如果您仍在使用 1.7,您应该更新到最新的 2.5,因为 1.7 行中存在严重的安全问题。)

In your code set do the following;在您的代码集中执行以下操作;

$app=JFactory::getapplication();
$app->redirect('index.php?option=com_users&view=login'));

You can achieve this with a plugin (at least in Joomla 3.x - not sure how far back this will work off-hand).您可以使用插件来实现这一点(至少在 Joomla 3.x 中 - 不确定这将在多远的时候立即起作用)。 Key here is the onUserAfterSave event, which tells you whether the user is new or existing.这里的关键是 onUserAfterSave 事件,它告诉您用户是新用户还是现有用户。

I wrote the code below some time ago, so can't recall the exact reason the redirect could not be done from within the onUserAfterSave event handler, but I think the redirect is subsequently overridden elsewhere in the core Joomla user management code if you try to do it from there, hence saving a flag in the session and checking it in a later event handler.我前段时间写了下面的代码,所以不记得无法从 onUserAfterSave 事件处理程序中完成重定向的确切原因,但我认为重定向随后会在核心 Joomla 用户管理代码的其他地方被覆盖,如果你尝试从那里开始,因此在会话中保存一个标志并在以后的事件处理程序中检查它。

class PlgUserSignupRedirect extends JPlugin
{
    public function onUserAfterSave($user, $isnew, $success, $msg)
    {
        $app = JFactory::getApplication();

        // If the user isn't new we don't act
        if (!$isnew) {
            return false;
        }

        $session = JFactory::getSession();
        $session->set('signupRedirect', 1);

        return true;
    }

    function onAfterRender() {
        $session = JFactory::getSession();
        if ($session->get('signupRedirect')) {
            JFactory::getApplication()->redirect('/my-post-signup-url');
            $session->clear('signupRedirect');
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM