Jump to content

Recommended Posts

This is an overly simplified example of what I am actually doing but you get the idea. I bet there's a better way to do this...

 

The code doesn't really make sense but you get the idea... I should also probably be checking that there's an act before showing a do or an action like

 

if(isset($_GET['act']) && $_GET['act'] == 'one' && $_GET['do'] == 'something') { ...

 

But that is besides the point, what is the best way of doing this? Should I just use another switch statement for each one or would that not work? Any input is appreciated.

 

<?php
switch($_GET['act']) {
    case 'one';
one();
break;
    case 'two';
two();
break;
    default:
one();
break;
}

function one() {
    if($_GET['do'] == 'something') {
        echo('Something.');
    }
    elseif($_GET['do'] == 'somethingelse') {
        if($_GET['action'] == 'dothis') {
            echo('Do this.');
        }
        elseif($_GET['action'] == 'dothat') {
            echo('Do that.');
        }
        else {
            echo('Something...');
        }
    }
}

function two() {
    // ...
}

?>

 

I already searched Google and couldn't find anything, just so you know... ;)

Link to comment
https://forums.phpfreaks.com/topic/73170-best-way-to-handle-multiple-_gets/
Share on other sites

Probably easiest to setup a seperate switch to deal with every $_GET var. eg;

 

<?php

  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      // run functions based on action.
    }
  }

  if (isset($_GET['view'])) {
    switch ($_GET['view']) {
      // run functions based on view.
    }
  }

  // etc etc

?>

I tried that then but then when I use functions from my class like $class->function(); within the include I get an error, or maybe I just did it wrong... I don't know I posted in OOP anyway. But at first I thought it was because it was within an include, then I tried it in the file itself and I still got the error.

 

Including isn't a bad solution anyway but it can get a little messy...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.