Jump to content

Recommended Posts

The code in my post does not work as you describe. I'm not sure you get what I am saying at all.

 

How exactly does my code end up trying to call action_Action_somefunction ? Its not, unless you pass ?page=action_somefunction through the url. But, as I said, the urls should remain as they always where using my code. eg; ?page=foo would execute actionFoo().

 

An example.

 

test.php

<a href="?page=foo>foo</a>
<a href="?page=bar>bar</a>
<a href="?page=bob>bob</a>
<?php

function actionFoo() {
  echo "This is foo";
}

function actionBar() {
  echo "This is bar";
}

function actionBob() {
  echo "This is bob";
}

function actionWelcome() {
  echo "this is welcome";
}

if (!isset($_GET['page']) || empty($_GET['page']) {
  actionWelcome();
} else {
  $menu_link = 'action' . ucfirst($_GET['page']);
  if (is_callable($menu_link)) {
    $menu_link();
  }
}

?>

The code in my post does not work as you describe. I'm not sure you get what I am saying at all.

 

How exactly does my code end up trying to call action_Action_somefunction ? Its not, unless you pass ?page=action_somefunction through the url. But, as I said, the urls should remain as they always where using my code. eg; ?page=foo would execute actionFoo().

 

Ah!  Ok you weren't that clear before about the URL that is the issue.  This code works now.

 

function main_page(){
if  (!isset($_GET['page']) || empty($_GET['page'])) {
	$menu_link = action_welcome_page;
	$menu_link();
}else{		
	$menu_link = 'action_' . ucfirst($_GET['page']);
	if (is_callable($menu_link)) {
		$menu_link();
	}
}		
} 

Ah!  Ok you weren't that clear before about the URL that is the issue.  This code works now.

 

You are kidding me?

 

Then, your url's would be unchainged from your previous code. eg; ?page=foo would execute actionFoo().

 

Maybe you just didn't read that part?

 

Sometimes helping out here is like banging my head on a wall. :)

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.