Page 1 of 1

Dynamic Menu using parameter passed via get and a require

Posted: Mon Mar 01, 2010 1:32 pm
by bob_brid
Please can someone help me with the following problem? I believe the code I have is rendering correctly but not being executed in time.

I've passed a parameter from one page to another anit recieves it OK (will echo out and display within the page fine).
I have also used requires for certain repeated elements of common pages.
I'm now trying to use the paramater to call one of a set of specific menu lists that are tailored to the parameter being passed between pages.

Code: Select all

echo "require('nav_".$PPP.".php')";


But it fails to call in the menu item correctly.

I can get it to create the following if $PPP passes 1

Code: Select all

<?php
require('nav_1.php');
?>
but it just writes it to the page rather than use it how I intended.

I can copy its output into a page and open that page and menu list 1 will appear.

Obviously this is not much use for a dynamic menu system.

Suggestion as to how I may get it to execute rather than display much appreciated.

Cheers,

Bob

Re: Dynamic Menu using parameter passed via get and a require

Posted: Mon Mar 01, 2010 2:20 pm
by requinix
"nav_1.php" is just a string. You can do whatever you want to it. Want 1 to be a variable instead? Go ahead.

Code: Select all

'nav_' . $PPP . '.php'
You can hand that off to require() perfectly fine.

Re: Dynamic Menu using parameter passed via get and a require

Posted: Mon Mar 01, 2010 5:04 pm
by AbraCadaver

Code: Select all

echo "require('nav_".$PPP.".php')";
Why are you echoing your require()? Why do you have quotes around your require()?

Code: Select all

require('nav_'.$PPP.'.php');

Re: Dynamic Menu using parameter passed via get and a require

Posted: Tue Mar 02, 2010 1:34 am
by bob_brid
Many thanks to both of you (tasairis & AbraCadaver),

I had been trying to use echo/print to dynamically write an include within an include to do what turned out easier than I was trying to make it.

Works a treat now.

Thanks again,

Bob