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 6540829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:01:43+00:00 2026-05-25T11:01:43+00:00

I use the class below to route all requests for php on my web

  • 0

I use the class below to route all requests for php on my web application. Can I improve upon this?

/*route*/

class route
  {
  function __construct($a) 
    {
    if(isset($_FILES['ufile']['tmp_name']))  // handles file uploads
      {
      new upload();
      }
    elseif(isset($_POST['a'])) // handles AJAX
      {
      $b=$_POST['a']; 
      switch($b) 
        {
        case '0': 
          new signin(); 
          break; 
        case '1': 
          new signup(); 
          break; 
        case '2': 
          session::finish(); 
          break; 
        case '3': 
          new bookmark('insert'); 
          break; 
        case '3a': 
          new bookmark('delete'); 
          break; 
        case '4': 
          new tweet(); 
          break;
        default:
          echo "ajax route not found";
          break;
        }
      } 
    elseif($a!=0)  // handles views
      {
      new view($a);
      }
    else
      {
      // route not found
      }
    }
  }

Verification(passes)

/*ROUTE
// Test Code - create entry
  new route(0);
  new route(1);
  $_FILES['ufile']['tmp_name']='test file';
  new route(0);
  unset($_FILES['ufile']['tmp_name']); 
  $_POST['a']=0;
  new route(0);
// Test Cases
  // Case 0:      echo "not routed: <br>";
  // Case 1:      echo "view created: $a <br>";
  // Case 2:      echo "file uploaded <br>";
  // Case 3:      echo "ajax responded: <br>";
*/
  • 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-05-25T11:01:44+00:00Added an answer on May 25, 2026 at 11:01 am
        public static function route($a)
        {
        // The first if statement is redundant this line will accomplish the
        // same as the if/else because if post[a] is not set it will become null
           $b=$_POST["a"];
        // now that b is a, it's really one switch statement
       if( $b==0 && $a==0 )
           switch( $b )
           {
             case '0':
               new signin();
               break;
             case '1':
               new signup();
               general::upload();
               break;
             case '2':
               session::finish();
               break;
             case '3':
               new bookmark('insert');
               break;
             case '3a':
               new bookmark('delete');
               break;
             case '4':
               new tweet();
               break;
             default:
               view::posts_all();
               break
           }
         }elseif( $a==1 )
             view::bookmarks();
         else
             view::posts_all();
    

    Give that a go, Good luck. (A side note: the quotation marks on the numeric cases are optional, the 3a is not. I left them in there because they were in the original. You could reduce it further by getting rid of $b entirely and running the switch on $_POST[‘a’] )

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

Sidebar

Related Questions

I am new to Mockito. Given the class below, how can I use Mockito
Can anyone recommend a ready-to-use class/library compatible with C/C++/MFC/ATL that would parse iCal/vCal/Google calendar
To simulate enums in PHP I like to use class constants. e.g. class FRUIT
In a web application, am I right to say inputs to the boundary class
When i use class-path attribute in spring XML file as below, <bean class=com.fritolay.suppliernet.common.lastresorthandler.impl.SingletonPropertiesRepository> <property
I use class from How to support Arabic text in Android? to show Arabic
I'm trying to use class names to change the color of a link after
I am trying to use Class::DBI with Catalyst::Plugin::Authentication::Store::DBIC. The example given on CPAN does
I have to use class Matrix4x4 from some 3rd party library, and I need
Is it better practice to use class variables, or the session cache in ASP.NET?

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.