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.

require_entry & if no_results generating PHP error

August 02, 2010 8:24pm

Subscribe [5]
  • #1 / Aug 02, 2010 8:24pm

    Leonard M

    24 posts

    On my single-entry page template, I have two places where I call in the channel content. In the title, I use

    <title>{exp:channel:entries channel="{my_channel}" disable="categories|category_fields|custom_fields|member_data|pagination"}{title}{/exp:channel:entries}</title>

    Then in the body of the page I use the same thing, except without the disable parameter, to display my content. E.g:

    {exp:channel:entries channel="{my_channel}"}<h1>{title}</h1>{body}{/exp:channel:entries}

    I’ve discovered that if I add require_entry=“yes”, followed by {if no_results}{redirect="404"}{/if} on the 2nd {exp:channel:entries} tag (in the body of my HTML page), then when I type in an invalid URL, I get the 404 page returned, but with PHP errors at the top:

    A PHP Error was encountered
    Severity: Notice
    
    Message: Undefined offset: 1
    
    Filename: libraries/Template.php
    
    Line Number: 1377
    
    A PHP Error was encountered
    Severity: Notice
    
    Message: Undefined offset: 1
    
    Filename: libraries/Template.php
    
    Line Number: 1378

    If I add require_entry=“yes”, followed by {if no_results}{redirect="404"}{/if} on the 1st {exp:channel:entries} tag (in my HTML title), typing in an invalid URL successfully returns my 404 page without any errors.

    <title>{exp:channel:entries channel="{my_channel}" disable="categories|category_fields|custom_fields|member_data|pagination" require_entry="yes"}{if no_results}{redirect="404"}{/if}{title}{/exp:channel:entries}</title>

    This is just a cosmetic thing (I’d prefer not to have all the conditional logic in my HTML title). I’m fairly sure in the past I could have two {exp:channel:entries} tags in the same template, and put the require_entry/if_no_results code in either instance and it would work.

    I wanted to post here first in case this was already reported in a way I didn’t find…this may be related to this thread in the archived forums: http://ellislab.com/forums/viewthread/154074 but this thread didn’t seem to lead to a bug report that I could find.

    (PS: My 404 page is defined!)

  • #2 / Aug 03, 2010 2:37am

    John Henry Donovan

    12339 posts

    Leonard,

    I can’t replicate this. Even in the example Agile Records single entry page template there are 2 channel:entries tags used in exactly the same way.

    What version and build of EE are you using?
    Was this a fresh install or an upgrade?
    Are you using any add-ons?

  • #3 / Aug 03, 2010 3:22am

    Leonard M

    24 posts

    It’s version 2.1.0 (build 20100712)

    No add-ons and a fresh install with Agile Records.

    I’ve narrowed it down to a snippet that I have on my 404 page that uses the {exp:channel:entries} tag to display information in a sidebar. When I take out that snippet from my 404 template, I don’t get this issue. When I change the snippet to pull from a different channel, I still get this issue. When I copy the code from the snippet and place it in the template, I also still get this issue.

    I also only get this issue when going to an invalid URL entry title on a valid template name or template group (an invalid template name or template group in my URL displays the 404 template ok). If recreating using Agile Records, an example invalid URL might be: http://www.example.com/index.php/news/comments/about_the_monkey. Putting about_the_monkey in segment 1 or 2 renders the 404 page just fine.

    (Sorry, this is kind of an obscure error.)

  • #4 / Aug 03, 2010 4:23am

    John Henry Donovan

    12339 posts

    Leonard,

    Thanks for all the detail. Can you also post what’s in your snippet so we can try with that please

  • #5 / Aug 03, 2010 9:23pm

    Leonard M

    24 posts

    {exp:channel:entries channel="faqs" limit="3" orderby="random" dynamic="off"} 
        <div id="{switch='colA|colB|colC'}">
          <h3>FAQ</h3>
    <p>      {faqs_question} <a href="http://{title_permalink=faqs/browse}">Find out…</a><br />
        </div><br />
      {/exp:channel:entries}

  • #6 / Aug 04, 2010 2:05pm

    Sue Crocker

    26054 posts

    Leonard, you’re a build behind.. can we get you to upgrade just so we’re on the same page?

  • #7 / Aug 04, 2010 11:31pm

    Leonard M

    24 posts

    I upgraded to 20100720 and I am still seeing this…

  • #8 / Aug 05, 2010 4:03am

    John Henry Donovan

    12339 posts

    Leonard,

    I have tried to replicate your issue and cannot.

    If you use the following swapping in your template group

    {if no_results}{redirect="site/404"}{/if}

    instead of

    {if no_results}{redirect="404"}{/if}

    What happens?

  • #9 / Aug 05, 2010 10:59pm

    Leonard M

    24 posts

    I don’t know why I didn’t think of this earlier….this error only happens in Chrome. (IE, Firefox, Safari all work fine).

    I can’t believe I didn’t think of checking different browsers earlier.

    So that makes this an even more obscure bug:

    a) You have to have 2 {exp:channel:entries} tags in your template, the 2nd of which has the require_entry and redirect parameter (it works fine if it’s in the 1st)
    b) The redirect must be to “404” - a redirect to a regular template does work fine
    c) The 404 template itself must have the {exp:channel:entries} tag
    d) The visitor must go to an invalid entry URL
    e) The visitor must be using Google Chrome

    It may actually be a bug with Chrome and not ExpressionEngine at all.

  • #10 / Aug 06, 2010 8:30am

    Sue Crocker

    26054 posts

    Don’t you just hate browser bugs? This does sound like it, and why John was unable to duplicate. Which version/build of Chrome is this with?

  • #11 / Aug 06, 2010 9:24am

    Leonard M

    24 posts

    Correction!

    It does happen in the other browsers…but it only comes up when I’m logged in. So, because I was logged in in Chrome, I saw it in Chrome. When I went to the other browsers, I didn’t log in first, so I didn’t see it.

    It also looks like it’s only super admins - I logged in as a regular member and didn’t see it either.

    It seems like with each thing I try, this gets more and more obscure. Next I’m going to discover it only happens when I’m logged in with a username beginning with L or something even more bizarre…

  • #12 / Aug 06, 2010 7:11pm

    Brandon Jones

    5500 posts

    Hi Leonard, by default PHP errors are only shown to Superadmins.

    I’m still not able to replicate this, albeit with the build released yesterday (20100805)

    Starting with a fresh install with the Agile Records theme, here’s what I did:

    1. news/index: replaced the existing html title tag with

    <title>{exp:channel:entries channel="news" disable="categories|category_fields|custom_fields|member_data|pagination"}{title}

    2. news/index: added the require_entry=“yes” parameter to the exp:channel:entries tag, and then immediately underneath that tag added:

    {if no_results}{redirect="404"}{/if}

    3. about/404: added the following inside #content_pri:

    {exp:channel:entries channel="news" dynamic="off"} 
          <h3>{title}</h3>
    <p>{/exp:channel:entries}

    4. Tried visiting: http://ee21/index.php/news/index/about_the_monkey and see the 404 page and a couple news entry titles; no PHP errors.

    Am I missing something?

  • #13 / Aug 07, 2010 12:25am

    Leonard M

    24 posts

    I downloaded the new build and installed it locally and followed your steps, and was also not able to recreate.

    However, I was able to recreate with some tweaks. I’ve tried to outline what I did differently:

    The news/index template doesn’t quite work for me…it has a {if segment_2 != ''}{redirect="404"}{/if} command at the top. When I removed that, I couldn’t get the 404 page to come up when I had an invalid entry.

    I therefore used news/comments instead. This template was mainly ready to go, except I had to change the channels to be just ‘news’. (I think there’s a typo in the <title> of this template: news_about instead of news|about.

    I also simplified the about/404 page to be as follows:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html >
      <head>
        <title>404</title>
      </head>
      <body>
          <h1>
            Page Not Found (404)
          </h1>
          
            The page you were looking for does not exist. There may
            be a spelling mistake in the URL in the address bar, or I
            may have removed this page. Please use the menu above 
            or on the right to visit a page that does exist.
          
     {exp:channel:entries channel="news" dynamic="off"} 
          {title}
    {/exp:channel:entries} 
      </body>
    </html>

    The Agile Records 404 page has a lot of embedded stuff in it, and for some reason the error doesn’t appear unless I take a lot of them out (I’m not sure why).

    I also recreated this on my live site, if you wanted to look at that instead. (I’d need to give you superadmin access)

    Sorry this is taking so much time for such a small thing…

  • #14 / Aug 07, 2010 5:36pm

    Greg Salt

    3988 posts

    Hi Leonard M,

    Let me try and recreate this and get back to you.

    Cheers

    Greg

  • #15 / Aug 08, 2010 4:55pm

    Greg Salt

    3988 posts

    Hi Leonard M,

    I can’t replicate this I’m afraid. So, let’s look at other reasons why this may be occurring for you. Where is your site hosted? Have you installed and run EE on this server before? Did you run the Server Wizard before installing?

    Cheers

    Greg

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

ExpressionEngine News!

#eecms, #events, #releases