Jump to content

parameter passing issue on function


Azarian

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. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.