Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-22-2007, 05:13 AM
unknown4's Avatar
Member
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 68
Default Php Templating

As most developers know you can use Php coding to template a website.
I have started this process however I came across a problem that has cause alot of distress for me.
The problem lies when I introduce a new directory. Using the code <?php include 'page.php'; ?> into a Php file makes the php template. However when i place a link to a file within another directory (eg <?php include 'folder/page.php'; ?>) it basically moves the file to the same directory. I realized I could either move everything into the same directory or rename every single link of about 800 pages.... Anyways what i am saying is there someway where i could make it work without moving or renaming links?
thanks
-unknown4
Reply With Quote
  #2 (permalink)  
Old 04-30-2007, 03:17 PM
Devil_Inc's Avatar
new member
 
Join Date: Apr 2007
Posts: 5
Default

why didnt you just use a mysql backend? that way your pages are to a minimum and its a breeze to backup or migrate to a different host.

`p34ce`
Ron
Reply With Quote
  #3 (permalink)  
Old 05-01-2007, 07:22 AM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Could you give us an example unknown? I'm not sure I get what you're asking - PHP shouldn't just move files from directory to directory (unless you're runnning a script that does that). Is it a paths problem so your specifying a path to another file and the paths are different depending upon the location of the original file.

Sorry that probably sounds like gibberish.

Hi Ron - are you saying that you keep all of your pages (rather than parts of a page) in a database?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #4 (permalink)  
Old 05-01-2007, 08:18 AM
unknown4's Avatar
Member
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 68
Default

lol Kev
its ok i understand .. atleast i think i do
heres basically what i mean.

I have home page "Home.php"
within that page i would have the code <?php include 'menu.php'; ?> ok
so thats templating thats the simple part where within home.php it will load menu.php
but when i have i have a directory eg forums/ and within it i have and different php and stuff
so what im saying is when i use <?php include 'forums/login.php'; ?> into Home.php it basically moves the php file

so say within login.php it has <?php include 'system.php'; ?> so that would open forums/system.php because its in the directory

but when i use it in Home.php it makes 'forums/login.php' into 'login.php'
so when login.php wants to access system.php which is meant to be within the same directory it just opens "can not find 'system.php' "

ummm yeah.. pretty confusing
i tried to make it as simple as i could
thanks
-unknown4
PS Home.php is not in any directories.
Reply With Quote
  #5 (permalink)  
Old 05-01-2007, 06:57 PM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

I still don't get it!


are you using / in front of your links ?????????? which takes you to the root of THAT directory??????
Reply With Quote
  #6 (permalink)  
Old 05-01-2007, 09:38 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

I think I get it - I think this is a relative paths problem where if you want to include a header in all your files and it's in /includes it's ok to use the relative path from a file in the home directory but it gets more complicated if you are using relative paths from other subdirectories and then a real pain in the arse when you start using includes that also include other files.

Is that about right unky4? Or am i barking up the wrong tree?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #7 (permalink)  
Old 05-02-2007, 07:10 AM
unknown4's Avatar
Member
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 68
Default

ooo kev understands
yea thats basically it, it gets annoying.
Reply With Quote
  #8 (permalink)  
Old 05-03-2007, 08:57 AM
Senior Member
 
Join Date: May 2007
Posts: 142
Default

Take it easy unkown, just use GLOBAL VARIABLES to indicate your PATH and let them loaded from you DB, so everytime you change anything just change the VARIABLE's context at the DB and your problem will resolve and don't use your links like the form of http://.... but just like ./$GLOBAL_PATH/$TEMPLATE_PATH/...

Tell us what will happen after.
Reply With Quote
  #9 (permalink)  
Old 05-03-2007, 09:05 AM
unknown4's Avatar
Member
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 68
Default

umm yes ....
I havn't entered anything into a database ......
sooo i do not really understand what you just wrote
Reply With Quote
  #10 (permalink)  
Old 05-03-2007, 09:25 AM
Senior Member
 
Join Date: May 2007
Posts: 142
Default

give me a simple line or two where you have always to change links , to applicate what I've said before on them.

Waiting for you
Reply With Quote
  #11 (permalink)  
Old 05-03-2007, 10:05 AM
unknown4's Avatar
Member
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 68
Default

If you actually read my post the links are right there ....
and you could always just use the index example .......

Last edited by unknown4; 05-03-2007 at 10:09 AM.
Reply With Quote
  #12 (permalink)  
Old 05-03-2007, 10:21 AM
Senior Member
 
Join Date: May 2007
Posts: 142
Default

I did unkown , I don't need the concept , I need the exact code , some thing like this :

Code:
include "c:/wamp/www/cnstats/cnt.php";

if (!eregi("index.php", $_SERVER['SCRIPT_NAME'])) {
    die ("Vous n'avez pas la permission d'ouvrir cette page seule...");
}

include ("./config/all.php");

echo $language ;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//FR">

<html>
<head>
	<title>La Ligue National Du FootBall</title>
	<link rel="stylesheet" type="text/css" href="style.css">
</head>

<?php


global $connection ;

$connection = Connecting() ;
//$db = mysql_select_db("lnfoot" , $connection) or die('there is no db with such a name');

session_start();
Reply With Quote
  #13 (permalink)  
Old 05-04-2007, 01:38 PM
unknown4's Avatar
Member
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 68
Default

All the codes i put into my site relating to this problem is right there...
Like I said, I entered nothing into any database, I havn't even created one
__________________
(\__/)
(='.'=)This is Bunny. Copy and paste bunny into your
(")_(")signature to help him gain world domination.
Reply With Quote
  #14 (permalink)  
Old 05-04-2007, 02:02 PM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

The only way i know of is to actually use full urls not relative paths.
I know it means changing all your links but can't see any other way.

If you use dreamweaver you can do this automatically using the change link sitewide option.

I use php for my included files, as in : ($_SERVER["DOCUMENT_ROOT"]."/includes/whatever_file.php") but in this day and age where it is preffered to have register globals turned OFF, it maybe more prudent to just use full urls
Reply With Quote
  #15 (permalink)  
Old 05-04-2007, 02:24 PM
Senior Member
 
Join Date: May 2007
Posts: 142
Default

Quote:
Originally Posted by unknown4 View Post
All the codes i put into my site relating to this problem is right there...
Like I said, I entered nothing into any database, I havn't even created one
I asked for what you wrote inside your files , but anyway let me give some advices:

1- Firs of all you should manage your templates dynamically and I can't make you examples with your explanations but I'll explain in other way.

2- Use one file to be shown on the URL, and the other pages are included as variables , let's take the simplest example and let's say I have a forum and a blog scripts:
the forum's path is /home/forum
the blog's path is /home/blog

in this case we should redirect them like /home/forum/index.php , /home/forum/login.php , /home/forum/system.php

and /home/blog/index.php , /home/blog/login.php ...etc

but how about :
Code:
/home/index.php?mod=forum&op=login , /home/index.php?mod=forum&op=sys
&
Code:
/home/index.php?mod=blog&op=login
and we add a function at the starting of the page like that:

Code:
$mod = $_GET['mod'] ;
$op  = $_GET['op'] ;

FuncSwitchEx($mod , $op) ;
and our function's code hould be something like that :
Code:
function FuncSwitch($mod , $op , $VldDel)
{
switch ($mod)
				{
					case forum:
						switch ($op)
						{
							case login:
								include ("./modules/forum/login.php") ;
								break ;
							case sys:
								include ("./modules/forum/system.php");
								break ;
							
							default:
								include ("./modules/forum/index.php");
								break ;
						}
					break ;

					case blog:
						switch ($op)
						{
							case login:
								include ("./modules/blog/login.php");
								break;
							
							default:
								include ("./modules/blog/index.php");
								break;
						}
						break ;
Oh I forget you should first divide your page template like this :

HEADER
LEFT MENU
BODY
RIGHT MENU
FOOTER

and just cut them using
Code:
<TABLE>
parsing , like that the forum or the blog or whatever it's will be loaded into the body's table just using the include function , this way you don't have to change the path each time and all files can be access usin './' as you're on your root directory.

If we want to get more pro we have to add a dynamic path function , it's simple by adding global variables like these :

$_HOME_PATH , $_MODULES_PATH ...etc

and put all our scripts as modules , so Forum will be just a module and so is Blog.

This way neither your menus will be displaced nor you have to change your links every time.

And there are more and more things you have to do , but it's good to start with like that.

Good luck buddy and don't get angry I was looking for your own script to tell you exactly what to do , but I think this one would help ,
Have a nice day

Last edited by ouahabix; 05-04-2007 at 02:30 PM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:27 AM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum