Page 1 of 1
having a switch within a switch using the URL as control
Posted: Mon Jul 24, 2006 7:03 pm
by MrPotatoes
well, that's my problem. i'm trying to use the URL to do the main switch statement and then i have another doing another within that main switch. here is what i'm doing:
this is the URL
http://localhost/framework/index.php?pe ... gin=forums
op=index -> this defines the main
adminPlugin=forums -> this is the switch that is within the switch
this is the main switch case:
Code: Select all
switch ('op')
{
case 'index':
// do stuff
break;
case 'process':
// do stuff
break;
default:
// oh noes. you suck
}
this is what i want to do:
Code: Select all
switch ('op')
{
case 'index':
break;
case 'adminPlugin': // remember this was explained up top :thumbup:
switch($adminPlugin)
{
case 'forums'
echo 'omg it worked!';
break;
}
break;
default:
// oh noes. you suck
}
so basically i'm stumped. i can do that second switch outside but what's the point? i don't think there is a good point to that. what do you think?
Posted: Mon Jul 24, 2006 7:10 pm
by John Cartwright
vs.
Although you still may want to check for the variables existance before using it.
Posted: Mon Jul 24, 2006 7:26 pm
by bike5
also don't forget the other ":"
Code: Select all
switch($adminPlugin)
{
case 'forums'
echo 'omg it worked!';
Code: Select all
switch($adminPlugin)
{
case 'forums':
echo 'omg it worked!';
Posted: Mon Jul 24, 2006 7:28 pm
by MrPotatoes
haha, ok. it's pusedo code. i already am doing that. i did that so you can read it better

Posted: Mon Jul 24, 2006 7:33 pm
by MrPotatoes
you can close this thread. i decided i know what i'm going to do. i'm not a fan but it works so i guess i'll quit bitchin. it's not as cool as i would like but whatever works works and i'm happy with that
less parsing as well so i guess i should stop complaining
Posted: Mon Jul 24, 2006 7:42 pm
by John Cartwright
MrPotatoes wrote:haha, ok. it's pusedo code. i already am doing that. i did that so you can read it better

Please let us know it is pseudo code then.
MrPotatoes wrote:you can close this thread. i decided i know what i'm going to do. i'm not a fan but it works so i guess i'll quit bitchin. it's not as cool as i would like but whatever works works and i'm happy with that
less parsing as well so i guess i should stop complaining
Well what did you decide to do? I don't think you were "bitching".. were here to help

Posted: Tue Jul 25, 2006 9:39 am
by MrPotatoes
first i have to say that you people post too fast lol
i'm already on the second page and it's not even been a full day!
secondly this is what i did mroe or less:
Code: Select all
switch ('op')
{
case 'index':
$this->renderAdmin('template.tpl');
break;
case 'adminPlugin':
// ?op=index&adminPlugin=a_Plugin_To_Admin
$dookie = $_GET['administrate'];
require_once 'plugins/_' . $dookie . '/admin/_' . $dookie . '.admin.php';
break;
default:
echo 'throw error here';
}
now, not thinking ahead of time that means that i've got to do the same to the other one. so i'm going to have to define one more URL param for this controller to work with and i'm good. i guess i've had to develop subcontrollers sooner than i thought. i knew i would have to but oh well. what can you do eh?
Posted: Tue Jul 25, 2006 11:50 am
by Jenk
I settled for multi-tier controllers.
main controller (index.php):
Code: Select all
<?
include_once 'includes/configs/config.php';
$page = (!empty(${'_' . $METHOD}['page']) ? ${'_' . $METHOD}['page'] : '');
if (!in_array($page, $CONFIG['WHITELIST']['PAGES'])) die ('invalid page action');
switch ($page) {
case 'auth':
$controller = 'auth.inc.php';
break;
case 'reg':
$controller = 'register.inc.php';
break;
//etc..
default:
$controller = 'welcome.inc.php';
}
include_once 'includes/controllers/' . $controller;
?>
auth.inc.php:
Code: Select all
<?php
$action = (!empty(${'_' . $METHOD}['action']) ? ${'_' . $METHOD}['action'] : '');
if (!in_array($method, $CONFIG['WHITELIST']['ACTION'])) die('Invalid action specified.');
switch ($action) {
case 'login':
$user = new User (${'_' . $METHOD}['user'], ${'_' . $METHOD}['pass']);
break;
//etc..
}
?>
Left out some stuff for the sake of making an example before anyone points it out.
Posted: Tue Jul 25, 2006 12:06 pm
by MrPotatoes
that's more-or less the way that i have it setup