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.

author_id == logged_in_member_id Issue

April 29, 2011 2:32pm

Subscribe [5]
  • #1 / Apr 29, 2011 2:32pm

    LucasHibbard

    61 posts

    Hello Everyone,

    I am using SafeCracker to bring the entry edit forms to the front-end of a site I’m developing, but I am running into a bit of an issue that I’m hoping I could get some help with.  When I do the following check to see if the author ID matches the currently logged in member id

    {if author_id == logged_in_member_id}

    I receive this PHP Error when I view the page as the author of the entry:

    A PHP Error was encountered

    Severity: Notice

    Message: Use of undefined constant TRUEFALSE - assumed ‘TRUEFALSE’

    Filename: libraries/Functions.php(650) : eval()‘d code

    Line Number: 9

    I’m not sure why this is happening, so any help would be very much appreciated.

    Thank you!

  • #2 / May 01, 2011 5:25pm

    Greg Salt

    3988 posts

    Hi Lucas,

    What is the context of this conditional? Can you show us the code for this template?

    Cheers

    Greg

  • #3 / May 02, 2011 9:42am

    LucasHibbard

    61 posts

    Hi Greg,

    Here is the code that I am using:

    <div class="cb-header">
    {exp:channel:entries channel="dml_entries" limit="1"}
      <ul class="article-links">
        <li{if "{embed:art_location}"=="read"} class="selected"{/if}><a href="http://{title_permalink=">Article</a></li>
        {if logged_in}
          {if "{locked}" == "No"}
        <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
          {/if}
          {if author_id == logged_in_member_id}
        <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
          {/if}
        {/if}
        {if allow_comments}
        <li{if "{embed:art_location}"=="discuss"} class="selected"{/if}><a href="#">Discuss</a></li>
        {if:else}
        <li class="disabled">Discussion is Disabled</li>
        {/if}
      </ul>
      {if logged_in}
      <ul class="article-actions">
        <li class="add"><a href="#">Add to Reading List</a></li>
        <li class="flag"><a href="#">Flag as inappropriate</a></li>
      </ul>
      {/if}
    {/exp:channel:entries}
    </div>

    This code is contained within it’s own file and embedded within other files.  Pretty much what I am trying to accomplish is to display the ‘Edit’ button only when the article is not locked or when the author is the currently logged in member.

    Thanks for your help,
    Lucas

  • #4 / May 03, 2011 1:59am

    John Henry Donovan

    12339 posts

    Lucas,

    Remove your conditional to outside of the {if logged_in} conditional and error will disappear and will work for you

  • #5 / May 03, 2011 10:34am

    LucasHibbard

    61 posts

    Hi John,

    Thanks for the help, but I’m still getting the PHP error that I was before.  Here is my new code:

    <div class="cb-header">
                            {exp:channel:entries channel="dml_entries" limit="1"}
                            <ul class="article-links">
                                <li{if "{embed:art_location}"=="read"} class="selected"{/if}><a href="http://{title_permalink=">Article</a></li>
                                {if author_id == logged_in_member_id}
                                <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
                                {if:elseif logged_in}
                                    {if "{locked}" == "No"}
                                <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
                                    {/if}
                                    {if allow_comments}
                                <li{if "{embed:art_location}"=="discuss"} class="selected"{/if}><a href="#">Discuss</a></li>
                                    {if:else}
                                <li class="disabled">Discussion is Disabled</li>
                                    {/if}
                                {/if}
                            </ul>
                            {if logged_in}
                            <ul class="article-actions">
                                <li class="add"><a href="#">Add to Reading List</a></li>
                                <li class="flag"><a href="#">Flag as inappropriate</a></li>
                            </ul>
                            {/if}
                            {/exp:channel:entries}
                        </div>

    Am I doing something wrong here?  Could it possibly be my EE install?  I’m starting to get really confused here as to why I’m having some of the issue that I am having when no one seems to be able to recreate them.

    Thank you for your help,
    Lucas

  • #6 / May 03, 2011 10:37am

    John Henry Donovan

    12339 posts

    Lucas,

    the {if logged_in} conditional can only be a simple one and not advanced like you just changed it to.

    This is what I meant by moving it outside. Not trying to nest again.

    {if logged_in}
          ....
    {/if}
          {if author_id == logged_in_member_id}
        <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
          {/if}
  • #7 / May 03, 2011 10:56am

    LucasHibbard

    61 posts

    John,

    Still getting the same error.  Updated code:

    <div class="cb-header">
      {exp:channel:entries channel="dml_entries" limit="1"}
        <ul class="article-links">
          <li{if "{embed:art_location}"=="read"} class="selected"{/if}><a href="http://{title_permalink=">Article</a></li>
          {if author_id == logged_in_member_id}
            <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
          {/if}
          {if logged_in}
            {if "{locked}" == "No"}
          <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
        {/if}
            {if allow_comments}
          <li{if "{embed:art_location}"=="discuss"} class="selected"{/if}><a href="#">Discuss</a></li>
            {if:else}
          <li class="disabled">Discussion is Disabled</li>
            {/if}
          {/if}
        </ul>
        {if logged_in}
          <ul class="article-actions">
        <li class="add"><a href="#">Add to Reading List</a></li>
        <li class="flag"><a href="#">Flag as inappropriate</a></li>
          </ul>
        {/if}
      {/exp:channel:entries}
    </div>

    Thanks,

  • #8 / May 04, 2011 11:20am

    Sue Crocker

    26054 posts

    Hi, Lucas.

    <li{if "{embed:art_location}"=="discuss"} class="selected"{/if}><a href="#">Discuss</a></li>

    See the <li{ - you’re missing the closing > right before {

    Does that help?

  • #9 / May 04, 2011 11:23am

    LucasHibbard

    61 posts

    Hi Sue,

    The closing > is actually at the other end of that if statement.  What I am trying to accomplish there is to add the class=“selected” to the li tag when the user is an the “discuss” page of that article.  Sorry for the confusion.  Thank you for your help though.

  • #10 / May 04, 2011 4:19pm

    Brandon Jones

    5500 posts

    Hi Lucas,

    Try stripping down this template until the conditional works, then slowly build it back up. That should expose the culprit in no time.

  • #11 / May 04, 2011 6:05pm

    LucasHibbard

    61 posts

    Hey Brandon,

    Okay, good advice.  I stripped the code down to the bare-bones and it worked without error.  As I added code back in, I found that what seems to be triggering the error is when I do the {if logged_in} check.  Here is my code as it stands now:

    <div class="cb-header">
      {exp:channel:entries channel="dml_entries" limit="1"}
      <ul class="article-links">
        <li{if "{embed:art_location}"=="read"} class="selected"{/if}><a href="http://{title_permalink=">Article</a></li>
        {if author_id == logged_in_member_id}
        <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
        {if:elseif "{locked}" == "No"}
          {if logged_in}
        <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
          {/if}
        {/if}
        {if logged_in}
        <li><a href="#">Discuss</a></li>
        {/if}
      </ul>
      {if logged_in}
      <ul class="article-actions">
        <li class="add"><a href="#">Add to Reading List</a></li>
        <li class="flag"><a href="#">Flag as inappropriate</a></li>
      </ul>
    {/if}
    {/exp:channel:entries}
    </div>

    Now, if you were to remove the logged_in check that is within the (if:elseif “{locked}” == “No”} conditional the PHP error goes away.  The problem with this though is that I need to only display the “Edit” link for logged in users.

    I hope this make sense.

    Thank you,
    Lucas

  • #12 / May 05, 2011 4:35pm

    Kevin Smith

    4784 posts

    Hey Lucas—

    Running that bit of the template on my end, this line seems to be at least triggering the problem:

    {if author_id == logged_in_member_id}

    When I remove it, everything works. If I just replace logged_in_member_id with ‘1’, it works as well, but this is actually a tag we use in the documentation, so it’s not a bad tag. Not that any of this is a solution yet, but I just wanted to post an update while I’m trying to find a workaround on my end.

    One thing that does concern me is the {title_permalink= inside your anchors. Maybe I’m missing it, but do you have the closing bracket somewhere? Removing them didn’t fix the problem on my end, but having them there could potentially cause problems. And just like Brandon suggested to you, I’m trying to test with the simplest version of this template possible.

    Have you made any headway since yesterday?

    Kevin

  • #13 / May 05, 2011 5:59pm

    LucasHibbard

    61 posts

    Hi,

    Actually, I was able to figure out how to fix this issue yesterday.  All that I needed to do was to pull the {if logged_in} conditional out side of the {exp:channel:entries} tag and that fixed the issue.  Here is my current(working) code:

    <div class="cb-header">
        {if logged_in}
        {exp:channel:entries channel="dml_entries" limit="1"}
        <ul class="article-links">
            <li{if "{embed:art_location}"=="read"} class="selected"{/if}><a href="http://{title_permalink=">Article</a></li>
            {if author_id == logged_in_member_id}
            <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
            {if:elseif "{locked}" == "No"}
            <li{if "{embed:art_location}"=="edit"} class="selected"{/if}><a href="http://{title_permalink=">Edit</a></li>
            {/if}
            {if allow_comments}
            <li{if "{embed:art_location}"=="discuss"} class="selected"{/if}><a href="http://{title_permalink=">Discuss</a></li>
            {/if}
        </ul>
    
        <ul class="article-actions">
            <li class="add"><a href="#">Add to Reading List</a></li>
            <li class="flag"><a href="#">Flag as inappropriate</a></li>
        </ul>
        {/exp:channel:entries}
        {if:else}
        <ul class="article-links">
            <li class="selected"><a href="http://">Article</a></li>
        </ul>
        {/if}
    </div>

    I’m not sure if this is the correct way that I should have fixed this issue, but it worked.  If someone has a better way to solve this problem, please let me know so that I can try it out.

    Thank you everyone for all of your help.

    Peace,
    Lucas

  • #14 / May 06, 2011 7:58am

    John Henry Donovan

    12339 posts

    Lucas,

    that solution looks fine to me. Closing this one out. Feel free to start a new thread if you have any more questions

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

ExpressionEngine News!

#eecms, #events, #releases