12 Replies - 1924 Views - Last Post: 07 October 2008 - 11:57 AM Rate Topic: -----

#1 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

menu logic suggestion

Post icon  Posted 29 September 2008 - 06:39 PM

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
//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 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
<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
$contents='link1';
require_once('template.php');
?>


link3.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 September 2008 - 06:59 PM


Is This A Good Question/Topic? 0
  • +

Replies To: menu logic suggestion

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: menu logic suggestion

Posted 29 September 2008 - 06:57 PM

You've got 5 separate pages for one menu. I can't see why you need more than 1 page.
Was This Post Helpful? 0
  • +
  • -

#3 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 204
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: menu logic suggestion

Posted 29 September 2008 - 07:00 PM

:code:

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.
Was This Post Helpful? 0
  • +
  • -

#4 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

Re: menu logic suggestion

Posted 30 September 2008 - 05:12 PM

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.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: menu logic suggestion

Posted 30 September 2008 - 07:05 PM

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.
Was This Post Helpful? 0
  • +
  • -

#6 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: menu logic suggestion

Posted 30 September 2008 - 07:39 PM

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
Was This Post Helpful? 0
  • +
  • -

#7 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

Re: menu logic suggestion

Posted 01 October 2008 - 06:14 PM

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
Was This Post Helpful? 0
  • +
  • -

#8 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 796
  • Joined: 25-February 08

Re: menu logic suggestion

Posted 01 October 2008 - 06:20 PM

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.
Was This Post Helpful? 0
  • +
  • -

#9 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

Re: menu logic suggestion

Posted 06 October 2008 - 12:33 AM

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
Was This Post Helpful? 0
  • +
  • -

#10 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 796
  • Joined: 25-February 08

Re: menu logic suggestion

Posted 06 October 2008 - 06:45 AM

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
$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.
Was This Post Helpful? 0
  • +
  • -

#11 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

Re: menu logic suggestion

Posted 07 October 2008 - 01:55 AM

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
Was This Post Helpful? 0
  • +
  • -

#12 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 796
  • Joined: 25-February 08

Re: menu logic suggestion

Posted 07 October 2008 - 08:04 AM

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.
Was This Post Helpful? 0
  • +
  • -

#13 dreamincodehamza  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: -12
  • View blog
  • Posts: 329
  • Joined: 12-September 08

Re: menu logic suggestion

Posted 07 October 2008 - 11:57 AM

I dont think so some where i need absolute path
but i think most of the projects links are based on
relative paths .. . including sub dir or any dir
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1