Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,579 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,942 people online right now. Registration is fast and FREE... Join Now!




menu logic suggestion

2 Pages V  1 2 >  
Reply to this topicStart new topic

menu logic suggestion

dreamincodehamza
29 Sep, 2008 - 05:39 PM
Post #1

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
ned to know that is this is a appropiate way of give path in the
menu or anything else you like to suggest me .
And
any other logic usully professional follow to make
dynamic menu paths/

config.php
php

<?php
//echo $docroot = $_SERVER['DOCUMENT_ROOT'].'<br>';
//echo __FILE__;
$docroot = $_SERVER['PHP_SELF'];
//$docroot = $_SERVER['DOCUMENT_ROOT'];
//$docroot = __FILE__;

$curPage = $PHP_SELF;
$curPage = path_get_last_arg($curPage);

$docroot = str_replace("\\","/",$docroot);
$docroot = str_replace($curPage,"",$docroot);


function path_get_last_arg($path){
$path = str_replace('\\', '/', $path);
$path = preg_replace('/\/+$/', '', $path);
$path = explode('/', $path);
$l = count($path)-1;
return isset($path[$l]) ? $path[$l] : '';
}
?>

menu.php
php

<?php require_once('config.php'); ?>
<table width="200" border="1">
<tr>
<td align="center"><h4> MENU </h4></td>
</tr>
<tr>
<td><a href="<?php echo $docroot; ?>link1.php">link1</a></td>
</tr>
<tr>
<td><a href="<?php echo $docroot; ?>link2.php">link1</a></td>
</tr>
<tr>
<td><a href="<?php echo $docroot; ?>link3.php">link1</a></td>
</tr>
</table>

template.php
php

<style>
.abc {
border: thin dotted #CCFF99;
color: #FF0066;
}
</style>
<table width="750" height="750" border="1" class="abc">
<tr>
<td colspan="3" align="center" height="80">header</td>
</tr>
<tr>
<td width="150" valign="top"><?php require_once('menu.php'); ?></td>
<td width="600"><?php echo $contents; ?>&nbsp;</td>
</tr>
<tr>
<td colspan="3" height="80" align="center">footer</td>
</tr>
</table>

link1.php
php

<?php
$contents='link1';
require_once('template.php');
?>

link3.php
php

<?php
$contents='link2';
require_once('template.php');
?>
same as
<?php
$contents='link3';
require_once('template.php');
?>


This post has been edited by William_Wilson: 29 Sep, 2008 - 05:59 PM
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: Menu Logic Suggestion
29 Sep, 2008 - 05:57 PM
Post #2

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 times
My Contributions
You've got 5 separate pages for one menu. I can't see why you need more than 1 page.


User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Menu Logic Suggestion
29 Sep, 2008 - 06:00 PM
Post #3

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,995



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
code.gif

it would be one thing to split it up into functions if you want to reuse the same code, but CTphpnwb is right, why are you splitting your menu into so many files? It only adds unnecessary complexity when conflicts arise.
User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Menu Logic Suggestion
30 Sep, 2008 - 04:12 PM
Post #4

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
so what would you like to suggest to me, and i have just make this menu logic
because i know this one only and want to know the actuall
tell me please how menu embeded in the webpages.
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: Menu Logic Suggestion
30 Sep, 2008 - 06:05 PM
Post #5

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 times
My Contributions
Basically, PHP manipulates data to do two things. One thing is to store/retrieve data in a database, and the other thing is to embed html code into a webpage. There is no single way to do it, and until we see something coherent that at least demonstrates what it is that you're trying to accomplish, there's not much we can do to help.

I would suggest that you better organize your thoughts and decide what you want your menu to look like and what you want it to do. Then you should be able to write code that efficiently accomplishes the task.



User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Menu Logic Suggestion
30 Sep, 2008 - 06:39 PM
Post #6

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 times
Dream Kudos: 350
My Contributions
Menus are just links, or images as links, or Flash that links to somewhere. You have the general principle down (though you're way off of making it easy).

All you need to do is link to the place where the file is, you don't need to do all of this PHP stuff. For the link, just make it <a href="link1.php">link</a>. This automatically takes the current directory and makes it link1.php. You're basically just making it harder on yourself
User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Menu Logic Suggestion
1 Oct, 2008 - 05:14 PM
Post #7

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
Actually what i want is that ---
On every website likes of every menu created dynamically .
and
i also need to create the menu dynamically.
that is what i want


User is offlineProfile CardPM
+Quote Post

akozlik
RE: Menu Logic Suggestion
1 Oct, 2008 - 05:20 PM
Post #8

D.I.C Addict
Group Icon

Joined: 25 Feb, 2008
Posts: 614



Thanked: 24 times
Dream Kudos: 750
My Contributions
Can you be more clear please? Precisely what do you want. When you say dynamic, do you mean you want to store the menu links in a database and generate them like that? Simply saying you want a dynamic menu doesn't say too much.
User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Menu Logic Suggestion
5 Oct, 2008 - 11:33 PM
Post #9

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
dynamic not means that i want to store the menu in database or want to get from database.

dynamic means that menu links path create on run time when page is loaded.
hope you are now clear.

And tell me how you create links in the menus
User is offlineProfile CardPM
+Quote Post

akozlik
RE: Menu Logic Suggestion
6 Oct, 2008 - 05:45 AM
Post #10

D.I.C Addict
Group Icon

Joined: 25 Feb, 2008
Posts: 614



Thanked: 24 times
Dream Kudos: 750
My Contributions
I see what you're saying.

You need to use the getcwd()

Check to see if the current working directory is root, if not, see if you're within a directory.

php

<?php
$rootDir = "htdocs"; // Change 'htdocs' to your root directory. Simply put the line "echo basename(getcwd());" at the root of your server and see what it shows
?>
<a href="<?= if (basename(getcwd()) != $rootDir) echo "../"; ?>pagename">Whatever</a>


What that does is check the basename of the current directory and see if it matches the name of the root directory. If not, it echoes out '../', which will move down one directory. This will work for a site that only has one directory structure.

Glad we were able to figure out what you wanted. What you were looking for was called dynamic path generation. Anyway, good luck with it and hope this helps.
User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Menu Logic Suggestion
7 Oct, 2008 - 12:55 AM
Post #11

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
yeah you got my point ---dynamic path generation--
if we have more then one directory structure then
this solution will be the best or any other one.

if i have 10 lessthenequal to 10 directory in my
project then
what kind of dynamic path generation
you like to suggest
User is offlineProfile CardPM
+Quote Post

akozlik
RE: Menu Logic Suggestion
7 Oct, 2008 - 07:04 AM
Post #12

D.I.C Addict
Group Icon

Joined: 25 Feb, 2008
Posts: 614



Thanked: 24 times
Dream Kudos: 750
My Contributions
It depends more on the number of levels in your site than the number of directories. If you have a ton of sub directories, you might want to consider using absolute links rather than relative ones. i.e., instead of

../index.php

You would use

http://www.yoursite.com/admin.php

That would solve your issue.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:26AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month