• Drupal 判断匿名用户必须先登录的解决方法


    要实现如果是匿名用户点击checkout链接,要求先登录

    方案一、通过添加Rules规则实现

    EVENT:After adding a product to the cart

    Conditions :User has role(s)  只选 匿名用户

    Action动作:Page redirect ,参数Parameter 网址填注册地址就行了 如: /user/register

    好处:实现容易

    坏处:其实并没有真正的满足需求,我们要做的是点击checkout链接时判断。

    方案二、自己写模块实现

    在sitesallmodulescustom目录下新建一目录,命名为goto

    然后再里面新建两个文件

    goto.info  这是模块信息文件

    ; $Id$
    name = Goto
    description = goto frontpage dispaly
    core = 7.x
    version = VERSION
    package = Goto
    
    files[] = goto.module

    goto.module 这是实现代码

    首先user_is_logged_in()函数判断用户是否登录

    如果没有登录在判断路径是否cart,如果是则跳转到user页面,在本项目中就是注册页面。

    <?php
    function goto_init(){
        if(!user_is_logged_in()){
    
            if(arg(0) == 'cart'){
            //if(arg(0)=='dev' and arg(1)=='cart'){
                //drupal_goto('user/register');
                drupal_goto('user');
            }
        }
    }
    ?>
  • 相关阅读:
    display ntp-service sessions
    display ntp-service status
    MySQL与telnet安装
    YL_组播_IGMPv2-v3
    YL_组播_PIM-DM协议原理
    YL_组播_IGMP协议原理
    IIS发布站点问题
    css 定位及遮罩层小技巧
    MYSQL查询某字段中以逗号分隔的字符串的方法
    零度
  • 原文地址:https://www.cnblogs.com/mafeifan/p/3578486.html
Copyright © 2020-2023  润新知