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.

Confusion with exp:channel:entries require_entry parameter [Resolved]

March 07, 2011 2:47pm

Subscribe [1]
  • #1 / Mar 07, 2011 2:47pm

    Chuck Liddell

    57 posts

    EE 2.1.4 build 20110201

    I am getting unexpected behavior from require_entry, and I was hoping you could shed some light on it for me.

    I am trying to pass a url_title as part of my URL.

    http://example.com/ee.php/about-us/

    I’ve configured the general settings so that http://example.com/ is my “root” folder and “ee.php” is my index file. The following code exists inside my “home” template (the one EE uses as the site root).

    This code works:

    {exp:channel:entries url_title="{last_segment}"}
      {title} - {url_title}
    {/exp:channel:entries}

    This code does not work (the title - url_title is not displayed) even though the entry does indeed exist:

    {exp:channel:entries url_title="{last_segment}" require_entry="yes"}
      {title} - {url_title}
    {/exp:channel:entries}

    The same URL is used for both code samples. Why does the second approach fail?

    I dug into the codebase to look for clues. I added echo statements to mod.channel.php on line 1397:

    echo "[" .$qstring . "]";
    $xe = explode('/', $qstring);
    $qstring = current($xe);
    echo "[" .$qstring . "]";

    The output is this:

    [ee.php/about-us][ee.php]

    mod.channel.php then proceeds to look for an article with the url_title “ee.php”, which of course does not exist.

    1) Why does require_entry only look at the very first segment and not each one? My best guess is that $qstring is supposed to have been modified in some way previous to this code line and the ee.php segment stripped, but that’s not happening for me.

    2) Why do you suppose I am seeing this behavior? Have I misconfigured something?

    I would prefer to use require_entry because it elegantly handles cases where url_title={last_segment}” does not produce a legitimate entry. If I use the first code example then a blank last_segment returns all entries in that channel, which is not ideal.

    Thanks in advance for your help! This one’s got me puzzled.

  • #2 / Mar 07, 2011 3:48pm

    Chuck Liddell

    57 posts

    After mulling it over a bit I believe this problem is related to the method that EE is using to parse URLs.

    Since I was only working on a main index template I didn’t notice that no other templates load correctly, either. Everything gets sent to that main index template.

    Going to explore this theory and see what shakes loose.

  • #3 / Mar 07, 2011 4:06pm

    Chuck Liddell

    57 posts

    Template resolution is having the same problem as I was having with the channel:entries tag.

    It is looking for a template called “ee.php”, and of course not finding it.

    My uri_protocol is set to “AUTO”.

    (0.000027) - Begin Template Processing -
    (0.018222) URI: ee.php/main/test
    (0.018253) Path.php Template: /
    (0.018279) Retrieving Template
    (0.018297) Parsing Template URI
    (0.173235) Showing index. Template not found: ee.php
    (0.173292) Retrieving Template from Database: main/index
    (0.182458) Template Found
  • #4 / Mar 07, 2011 4:24pm

    Chuck Liddell

    57 posts

    My EE install is setting “ee.php” (my renamed index.php) as segment_1, which is causing all of the pathing problems.

    The documentation http://ellislab.com/expressionengine/user-guide/templates/globals/url_segments.html indicates that this shouldn’t be the case.

    Still trying to figure out why the URL is parsing the way it is.

  • #5 / Mar 07, 2011 4:49pm

    Chuck Liddell

    57 posts

    Ladies and gentlemen, we have a winner!

    /*
    |--------------------------------------------------------------------------
    | URI PROTOCOL
    |--------------------------------------------------------------------------
    |
    | This item determines which server global should be used to retrieve the
    | URI string.  The default setting of "AUTO" works for most servers.
    | If your links do not seem to work, try one of the other delicious flavors:
    |
    | 'AUTO'            Default - auto detects
    | 'PATH_INFO'        Uses the PATH_INFO
    | 'QUERY_STRING'    Uses the QUERY_STRING
    | 'REQUEST_URI'        Uses the REQUEST_URI
    | 'ORIG_PATH_INFO'    Uses the ORIG_PATH_INFO
    |
    */
    $config['uri_protocol']    = 'REQUEST_URI';

    Problem solved. URI protocol was indeed the culprit for all the strange behavior I was encountering.

    Just wish I had noticed that templates weren’t working earlier than I did. Would have saved me some pain and misery.

    Feel free to close out this thread.

  • #6 / Mar 07, 2011 4:51pm

    Ingmar

    29245 posts

    Thanks for letting us know. Please don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases