Jump to content

Constant Variable


vicodin

Recommended Posts

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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