vicodin Posted July 15, 2008 Share Posted July 15, 2008 I am working on creating like a framework for my site and i want to create a constant variable like $pagename = "Index" and now when i include my functions and i call for the variable $pagename will it look at the constant variable $pagename? If it will not how do i get it to use the constant? Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 15, 2008 Share Posted July 15, 2008 i'm afraid I don't understand your question.. are you trying to like say make an index.php page.. and then to navigate through your site pages make links like this?: http://yoursite.com/index.php?p=index Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 15, 2008 Share Posted July 15, 2008 are you talking about normal constants or class constants? normal constants don't have $ signs on them. once declared, they are global and can be seen by any function/class. here is info on how to use them: http://us.php.net/constants Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 15, 2008 Share Posted July 15, 2008 it sounds like via the "$pagename" variable that he wants to use it for navigation Quote Link to comment Share on other sites More sharing options...
vicodin Posted July 15, 2008 Author Share Posted July 15, 2008 Ok i am making a function so that what ever page i'm on it wont make it a link in my navigation. So i want to declare in what ever page it is the $pagename and i want my functions to pick up on $pagename and use that. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 15, 2008 Share Posted July 15, 2008 preferably, pass it as an argument to the function. if this isn't an option, you can try using the global keyword: http://us2.php.net/global Quote Link to comment Share on other sites More sharing options...
ag3nt42 Posted July 15, 2008 Share Posted July 15, 2008 hmm, I use a similar thing for my pages.. where I have an index page then all my other site pages are included to that page... and I just use the "$_GET" to change includes.. index.php: <?php if(isset($_GET['p'])) { if($_GET['p']=='home') { include('home.php'); } } ?> then the navigation links on my site look like this http://mysite.com/?p=index i think it works rather well myself Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 The words Constant and Variable contradict each other. Quote Link to comment Share on other sites More sharing options...
JD* Posted July 15, 2008 Share Posted July 15, 2008 You can also just get the name of the current page with this: <?php $this_page = basename($_SERVER['REQUEST_URI']); if (strpos($this_page, "?") !== false) $this_page = reset(explode("?", $this_page)); ?> Just clean up the string a bit more and you'll always know where you are. Quote Link to comment Share on other sites More sharing options...
vicodin Posted July 15, 2008 Author Share Posted July 15, 2008 This does work. Function... function linkto_unlesspage($name,$link,$extra = NULL){ $pagename = constant("page"); if (!($name == $pagename)){ echo '<a href="'.$link.'" '.$extra.'>'.$name.'</a>'; }else{ echo $name; page... define("page","Home"); include('func.inc'); linkto_unlesspage("Home","index.php"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.