ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP and Member Global Variables

February 23, 2009 8:48pm

Subscribe [2]
  • #1 / Feb 23, 2009 8:48pm

    Chad Altemose

    44 posts

    Ok forgive me if this is answered in the forums somewhere - and i’m sure it is - but i dug and couldn’t find an answer.

    Why doesn’t this code work as expected:

    <?php
    echo "{group_title}" . "
    ";
    if ("{group_title}" == "Super Admins") echo "Super Admins";
    else echo "Normal Folk";
    ?>

    If i am logged in as a super admin, the group title conditional doesn’t evaluate to true even though it seems like it should. And to make matters worse, I’m using code that’s not drastically different from this elsewhere and it works. The big differences are that it’s not using global variables (instead, results from ee loops) and it’s comparing ee database values stored in my PHP to other ee database values.

    If you execute the above code logged in as a Super Admin you see:

    Super Admins
    Normal Folk

    When you should see 2 lines of “Super Admins” instead of the line “Normal Folk.”

    I’ve got to be missing something really simple.

    Yes, my template has PHP enabled (output).

    If i run PHP’s string replacement on the group title value, it does NOT find the space character which initially lead me to believe that it was just how the space was encoded (or something like that). But i’m having the exact same problem if i use an EE loop and compare a field out of the database that has a group id stored in it (as a string obviously) to the logged_in_group_id global variable.

  • #2 / Feb 23, 2009 9:14pm

    Greg Aker

    6022 posts

    Greetings Chad:

    If you are going to be using that much PHP, I’d recommend using the EE Session Class.

    Give that a try, and see if that helps.

    -greg

  • #3 / Feb 23, 2009 9:32pm

    Chad Altemose

    44 posts

    Thanks. I can’t explain why i didn’t use that in the first place other than “it’s monday.” Not a good excuse but i’m sticking with it.

    I will continue down that path - however - i’m still curious about why the above code doesn’t work. Any thoughts?

  • #4 / Feb 24, 2009 1:59am

    John Henry Donovan

    12339 posts

    Chad,

    The reason your original code is not working is because of EE’s parse order. I would recommend you checking out the following Wiki article.

    EE Wiki : Parse Order

    You mentioned you had trouble originally with an EE loop. What was your original goal with this loop?

    Would something like this help?

    {if group_title == "Superadmins"}content{/if} {if group_title == "members"}content{/if}
  • #5 / Feb 24, 2009 2:37am

    Chad Altemose

    44 posts

    That parse order article is quite useful. I had a feeling that was the reason for my code not working as expected.

    Your solution works great, and i thought about going that route, but i have some dynamic stuff going on for members groups and so Greg’s suggestion of the session class works the best for me.

    Thanks for the help fellas.

  • #6 / Feb 24, 2009 3:13am

    John Henry Donovan

    12339 posts

    Glad you got it sorted. Feel free to post again if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases