How to get the user language after logged in?

Discussion in 'aMember Pro v.4' started by incirus, Mar 2, 2012.

  1. incirus

    incirus New Member

    Joined:
    Feb 27, 2012
    Messages:
    21
    What is the method to get the user language?

    Is there any easy way like;
    Am_Lite::getInstance()->getUserLANG()
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    $user = Am_Lite::getInstance()->getUser();
    echo $user['lang'];

  3. incirus

    incirus New Member

    Joined:
    Feb 27, 2012
    Messages:
    21
    Hey Alex,

    Thanks for the reply.
    I can pull the user info but lang is empty.
    I have set 3 languages and language selection works on the amember member area but when I use the above method I gives empty nothing.

    I also get the below error on some occasions. So there might be some issue somewhere.

    A PHP Error was encountered

    Severity: Notice
    Message: Undefined index: lang
    Filename: Am/Lite.php
    Line Number: 96
  4. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    What is line 96 of your amember/library/Am/Lite.php file?

    Look at aMember database - "am_user" table. Is the field "lang" filled-in?
  5. incirus

    incirus New Member

    Joined:
    Feb 27, 2012
    Messages:
    21
    Some of the users have language but some do not have anything (NULL) in that field.
    Default language is English so if their language is English they dont make any language selection and this creates the error.
    I guess if user makes a selection than that table field is filled otherwise it is not.
    But my question is related to language selection.
    When a user choose the language or not choose the language, how can I detect the current language.
    Your solution works only if the user makes any selection. If they don't make the selection it gives the above error.
  6. incirus

    incirus New Member

    Joined:
    Feb 27, 2012
    Messages:
    21
    And also, you did a really good job Alex.
    Thanks.
  7. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Just make this in your code.
    Like echo empty($user['lang']) ? 'en' : $user['lang'];

    Thank you!

Share This Page