【问题标题】:Joomla JUser getinstance QuestionsJoomla JUser getinstance 问题
【发布时间】:2010-05-24 17:03:01
【问题描述】:

我正在尝试制作一个身份验证插件。 JUser::getInstance() 接受一个输入,它应该是 id。有没有办法使用其他标识符来获取用户的实例?例如用户名、电子邮件等。

【问题讨论】:

    标签: plugins joomla joomla1.5


    【解决方案1】:

    可能没有这样的方法。但是是的,如果您确定用户名或电子邮件是唯一的,那么您可以在 library/joomla/user/ 中修改您的文件 user.php 并在那里添加一个方法。

    getInstanceByEmail($email)
    {
         $query = "select id from jos_users where email=".email;
         // use the code to get the id;
        return getInstance($id);
    } // this is just a sample code of how it can be achieved
    

    【讨论】:

    • 谢谢,不知道为什么没想到>.>
    【解决方案2】:

    由于 Joomla 自己的身份验证是通过检查用户的用户名(当然还有密码)来完成的,所以它必须是唯一的。是的,您可以执行@Rixius 建议的操作。

    这是我的版本:

        // Get a database object
        $db     = JFactory::getDbo();
        $query  = $db->getQuery(true);
    
        $query->select('id, password');
        $query->from('#__users');
        $query->where('username=' . $db->Quote($credentials['username']));
    
        $db->setQuery($query);
        $result = $db->loadObject();
        $user = JFactory::getUser();
    
        if ($result)
        {
            $user = JUser::getInstance($result->id);
        }
    

    【讨论】:

      猜你喜欢
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      • 2011-10-22
      • 2013-06-30
      • 2013-09-26
      • 2011-06-16
      • 1970-01-01
      相关资源
      最近更新 更多