Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:49:35+00:00 2026-06-16T04:49:35+00:00

I am using PHP to layout a navigation menu and display content according to

  • 0

I am using PHP to layout a navigation menu and display content according to the URL.

I have reached the IF-ELSE stack that determines what content to show (by loading the necessary classes and/or methods). But there has to be a better way of writing this.. any suggestions?

BreadCrumbs::getCrumb() is a static method used to retrieve an element saved from the URL based on the index value (URI Request, split by ‘/’, then saved in array).

…(ArrayHelp::recValueSearch(BreadCrumbs::getCrumb(2), Config::getNavPrimary()) checks the URI element against the array containing the navigation list from the Config class.

BreadCrumbs::setEmptyCrumb(1, “home”) runs a method which sets a default value if the value is either not present or not valid (in the nav list array)

<?php
// set bread crumbs
BreadCrumbs::setCrumbs($_SERVER['REQUEST_URI']);
BreadCrumbs::setEmptyCrumb(1, "home");
BreadCrumbs::setEmptyCrumb(2, "all");



if (BreadCrumbs::getCrumb(1) == 'about') {
    echo 'This is the <b>About</b> Page';
}
else if (BreadCrumbs::getCrumb(1) == 'contact') {
    echo 'This is the <b>Contact</b> Page';
}
else if (BreadCrumbs::getCrumb(1) == 'search') {
    echo 'This is the <b>Search</b> Page';
}
else if (BreadCrumbs::getCrumb(1) == 'home') {
    if (BreadCrumbs::getCrumb(2) == 'all') {
        echo 'This is the <b>Home</b> Page';
    }
    else if (ArrayHelp::recValueSearch(BreadCrumbs::getCrumb(2), Config::getNavSecondary())) {
        echo 'This is the list page for category: <b>' . BreadCrumbs::getCrumb(1) . '</b> and the country filter is: <b>'. BreadCrumbs::getCrumb(2) . '</b>';
    }
    else {
        echo 'change filter value and go to the <b>home</b> page';
    }
}
else if (ArrayHelp::recValueSearch(BreadCrumbs::getCrumb(1), Config::getNavPrimary())) {
    if (BreadCrumbs::getCrumb(2) == 'all') {
        echo 'This is the list page for category: <b>' . BreadCrumbs::getCrumb(1) . '</b> and the country filter is <b>all countries</b>';
    }
    else if (ArrayHelp::recValueSearch(BreadCrumbs::getCrumb(2), Config::getNavSecondary())) {
        echo 'This is the list page for category: <b>' . BreadCrumbs::getCrumb(1) . '</b> and the country filter is: <b>'. BreadCrumbs::getCrumb(2) . '</b>';
    }
    else {
        echo 'change filter value to all and go to category: <b>' . BreadCrumbs::getCrumb(1) . '</b>';
    }
}
else {
    echo 'redirect page to home/all';
}

?>

EDIT: Changed to Switch Statement as below, a little better..

    <?php
    $array_helper = new ArrayHelp;
    $valid_primary = $array_helper->recValueReturn(BreadCrumbs::getCrumb(1), Config::getNavPrimary());
    $valid_secondary = $array_helper->recValueReturn(BreadCrumbs::getCrumb(2), Config::getNavSecondary());
    switch (BreadCrumbs::getCrumb(1)) {
        case 'about' :
        case 'contact' :
        case 'search' :
            echo 'This is the <b>' . BreadCrumbs::getCrumb(1) . '</b> Page';
            break;
        case 'home' :
            switch (BreadCrumbs::getCrumb(2)) {
                case 'all' :
                    echo 'This is the <b>Home</b> Page';
                    break;
                case ($valid_secondary[1]) : 
                    echo 'This is the list page for category: <b>' . BreadCrumbs::getCrumb(1) . '</b> and the country filter is: <b>'. BreadCrumbs::getCrumb(2) . '</b>';
                    break;
                default:
                    echo 'change filter value and go to the <b>' . BreadCrumbs::getCrumb(1) . '</b> page';
                    break;
            }
            break;
        case ($valid_primary[1]) :
            switch (BreadCrumbs::getCrumb(2)) {
                case ($valid_secondary[1]) : 
                    echo 'This is the list page for category: <b>' . BreadCrumbs::getCrumb(1) . '</b> and the country filter is: <b>'. BreadCrumbs::getCrumb(2) . '</b>';
                    break;
                default:
                    echo 'change filter value and go to the <b>' . BreadCrumbs::getCrumb(1) . '</b> page';
                    break;
            }
            break;
        default:
            echo 'redirect page to home/all';
            break;
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:49:36+00:00Added an answer on June 16, 2026 at 4:49 am

    If your example code shows your complete requirements some of it could be greatly simplified by just using the actual string returned by getCrumb:

      $crumb = ucfirst(BreadCrumbs::getCrumb(1));
      switch($crumb){
    
         case 'home': case 'foobar': # etc, etc
            echo "This is the <b>$crumb</b> Page";
            break; # or add some extra logic
         default:
            # handle invalid crumbs here
            break;
      }
    

    (ucfirst is used to make the first character of the string uppercase.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Layout using ExtJs. It consists of a left menu and
I am currently using jQuery to load a variable php layout depending on the
I need to update multiple embedded docs in mongo using PHP. My layout looks
What's the best way to create an HTML document using PHP? I find that
I am not very experienced with PHP. I have a site I'm maintaining that
I have simple table that has about 80 rows, which I populate dynamically using
I have a very simple chat system I've built using PHP and MySQL (this
My goal is to have dynamic Facebook like buttons using a php variable in
I am not using flash or php - and I have been asked to
Hi I am currently using jQuery to load a variable php layout depending on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.