title: PHP Codeigniter Multiple Level Switch Statements
body: <p>I am re-building a website with PHP codeigniter that contains mostly static pages and some dynamic pages interspersed. The problem is, the pages are 1-5 layers deep within the navigation (ex. example.com/about/history/people/person/photos). </p>
  
  <p>I'm not sure how to implement this in the controller. I currently have a crazy set of switch statements nested in switch statements. Here is a simple example:</p>
  
  <pre><code>class About extends MY_Controller 
  {
  //**** INDEX page ****                    
  public function index()
      {
          $this-&gt;setTitle('About');
          $this-&gt;setDescription('About Stuff');
          $this-&gt;loadView('about/index');
      }
  
   //-------------------------HISTORY section--------------------------------
  public function history($sub1 = "", $sub2 = "", $sub3 = "", $sub4 = "")
  {
      $path = "";
  
      switch($sub1){
  
          //_____ PEOPLE section ____
          case 'people':
              switch($sub2){
  
                  //____ PERSON section ____
                  case 'person':
                          switch($sub3){ 
  
                              //**** PHOTOS page ****
                              case 'photos':
                                  $this-&gt;setTitle('Photos');
                                  $this-&gt;setDescription('Photo stuff');
                                  $path = 'people/person/photos';
                                  break;
  
                              //**** DOCUMENTS page ****
                              case 'documents':
                                  //Load special scripts
                                  $this-&gt;setTitle('Documents');
                                  $this-&gt;setDescription('Document stuff');
                                  $path = 'people/person/documents';
                                  break;
  
                               //**** INDEX page ****
                               default:
                                  $this-&gt;setTitle('Person');
                                  $this-&gt;setDescription('Person stuff');
                                  $path = 'people/person/index';
                          }
                          break;
  
                  //**** AnotherPerson page *****
                  case 'anotherPerson':
                       //Load database
                       $this-&gt;setTitle('AnotherPerson');
                       $this-&gt;setDescription('AnotherPerson stuff');
                       $path = 'people/anotherperson';
                       break;
  
                  //**** INDEX page ****
                  default:
                      $this-&gt;setTitle('People');
                      $this-&gt;setDescription('People stuff');
                      $path = 'people/index';
  
              }
              break;
  
  
          //**** INDEX page ****
          default:
              $this-&gt;setTitle('History');
              $this-&gt;setDescription('History stuff');
              $path = 'index';
      }
  
  
              $this-&gt;loadView('about/history/' . $path );
  
  }
  }
  </code></pre>
  
  <p>I feel like I am approaching this incorrectly and it feels messy. So my question is: Is there a better (more compact/clean/dynamic) way of doing this? </p>