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.

using segs[2] within template

November 08, 2010 5:32pm

Subscribe [4]
  • #1 / Nov 08, 2010 5:32pm

    Brad Morse

    428 posts

    giving error Notice: Undefined offset: 2

    for this line: $seg2 = $IN->SEGS[2];

    function displaySurvey() {
        global $IN;
    
        $seg2 = $IN->SEGS[2];
    
        if($seg2) {
            switch($seg2) {
                case 1601:
                    $url = "444053F83FBF9C31";
                break;
        
                case 1802:
                    $url = "D66C9BD62F40C3CF";
                break;
        
                case 2107:
                    $url = "7023023BC27C7F99";
                break;
        
                default;
                    $url = NULL;
                break;
            }
        }
    }

    works fine when the URL is domain.com/segment_1/segment_2

    but if the URL is domain.com/segment_1/ - it gives me that error.

    it is expecting a value to be stored within $seg2, but I do not know how to “shut it up”.

    Any help is appreciated.

    EE v1.6.9 20100415

  • #2 / Nov 08, 2010 6:28pm

    Wouter Vervloet

    758 posts

    Can’t you just build in a check to see if it is set?

    $seg2 = isset($IN->SEGS[2]) ? $IN->SEGS[2] : false;
  • #3 / Nov 09, 2010 12:15am

    Brad K Morse

    178 posts

    Thanks - that worked.

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

ExpressionEngine News!

#eecms, #events, #releases