homepage Welcome to WebmasterWorld Guest from 54.204.127.191
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Dynamic page questions
Just a few minor questions...
Echo_Tyme




msg:1280653
 8:46 pm on Jul 16, 2004 (gmt 0)

Some of you know I was looking on how to make a template, seeing how it's nearly impossible at this time i'm going to upgrade my current dynamic pages, I have a few questions i'm hoping you can all help me with.

Right now I use php require to call up the head, two sides and the footer. I see alot of people use php include... what's the dif and what's better with include?

Also can I have a dynamic page call up another dynamic page? I'm sure you can but is it wise.

In the <title> tag, is there a way to call up a page taht I want? Like since my layouts change and I don't want to go through every page and cut and paste codes, is there a way to just call up a .txt file that I want shown. I have one do this in the body, but can it be done in the title.

Now one question with templates that still is getting to me, alot of people are using $content=... but when you have alot of pages... why would u have that... unless there is a way... like a database... ah...

So you have that call up a page the user requested and it's stored in a database... Wouldn't a database in php terms be just another file with all the pages listed with an ID? Then have the $content= call up from that page whatever the person called for?

Haha frustrating yes, but it really helps me out ^.^ Thank you!

 

ergophobe




msg:1280654
 9:14 pm on Jul 16, 2004 (gmt 0)

There used to be more difference between the two, but now the only difference is in the way they handle failure. Upon failure include issues a warning and require causes a fatal error. See

[us2.php.net...]


Also can I have a dynamic page call up another dynamic page?

I don't know what you mean. You mean one page that redirects to another? That's absolutely fine depending on circumstances.


In the <title> tag, is there a way ... to just call up a .txt file that I want shown.

<title><? include('title.txt');?> </title>


alot of people are using $content=... but when you have alot of pages... why would u have that.

Because you do all your processing and put your page into variables like $title, $content, etc. Then all your template does is variable substitution like

===== file: my_page.php ========
<?
include('settings.php');
$content = "<p>This is my content from my database, files or wherever I get it.</p>";
$title = "Title of the page from my database";

include('default_template.php');
?>

======== end file my_page.php ==============

===== file: default_template.php ========

<html>
<head>
<title><?=$title?></title>
</head>
<body>
<?
include('header.inc.php');
include('left_nav_box.inc.php');
echo $content;
include('footer.inc.php');
?>
</body>
</html>

=========== end file ===========

Echo_Tyme




msg:1280655
 12:14 am on Jul 17, 2004 (gmt 0)

I c... so in your settings.php you have all the things laid out, like the $content and $title of the page right?

So the page would be like...

$title=home

$content=welcome

then when you call it up it prints what you call on the page, correct?

Then you have the layout come after (but wouldn't it have to be called before to make it all show up correctly?).

Then in your template page is "?" the title? because the code was <title><?=$title?></title> make it look like? was the value of $title. Oh no your asking what is the title, and it equals $title oops.

And I meant if I have a dynamic page (side.php) call up something like... (version.txt) is it safe, i'm already doing it so it was stupid to ask, but i figured it out after i asked...

Now this opens doors for me...

If I have one page that has all the different headers and footers of pages... then I call up the page and the value... that's fine... correct? I can show you an example if you'd like but you just helped me alot (if all be true) otherwise i'm more confused lol.

Thanks for the answer :)

ergophobe




msg:1280656
 12:27 am on Jul 17, 2004 (gmt 0)

No, the settings.php file is for sitewide settings that will be used for pretty much every page (start sessions, define constants, etc etc).

I also initialize variables
$content = "";
$title ="";

so I don't get errors.

Then page.php defines $title and $content for that page.

Finally, at the end of page.php, I include the template which defines layout.


call up something like... (version.txt

Fine. Though it's easier to keep track of to use an extension that corresponds to content
.txt if no markup
.html if no php
.php if there is php

I think this article will help you get your head around things:

[zend.com...]

Echo_Tyme




msg:1280657
 1:09 am on Jul 17, 2004 (gmt 0)

So the settings.php is for like the title and headers and stuff right? Don't work for me it's all variables up there.

So I CAN make a page taht is all variables and call from them right?

And u make the end of the page the template, i c i c... I think i'm gettin git...

So have the variables, then make a page that calls on these variables. and then wrap the layout around this in a page that is called after all this... I think I get it... if i'm right that is ^.~

Echo_Tyme




msg:1280658
 8:16 am on Jul 17, 2004 (gmt 0)

Ok... I tried the first thing... it worked, i made my adjustments and it was great... then I added more and it's f'd up...

Right now i have the template to just:

echo $content;

$content is a variable in the page originally being called, yet it keeps giving me an error that the variable doesn't exist!

It's REALLY basic!

---template---

<html>
<head>
<title><?=$title?></title>
</head>
<body>
<?
echo $content;
?>
</body>
</html>

-end-

---page---

<?

$content="<p>This is my content from my database, files or wherever I get it.</p>";
$title="Title of the page from my database";

include('/template.php');
?>

--end--

what can POSSIBLE be wrong!?!? The template keeps bring up an error on line 7 which is the echo $content'! Waht is going wrong >.<

(sighs) so close! lol.

[edited by: jatar_k at 1:36 am (utc) on July 18, 2004]
[edit reason] removed url [/edit]

ergophobe




msg:1280659
 4:09 pm on Jul 17, 2004 (gmt 0)


So the settings.php is for like the title and headers and stuff right?

No. It is for sitewide setting that will be used on every page, like initializing the database connection. Including fundamental classes and function libraries that will be used on every page. There is NO HTML there.

I put my doctype, html tag and all that in the template. The page variables then get thrown into to the template, which also has include statements for the page header (that's the header AS VIEWED not the stuff in the <head> tag; you can put that in the template or in an included file. I put it in the template and add any page-specific html there that I need with page-specific variables in page.php).

Tom

ergophobe




msg:1280660
 6:43 pm on Jul 17, 2004 (gmt 0)

What is the error message?

Tom

Echo_Tyme




msg:1280661
 12:57 am on Jul 18, 2004 (gmt 0)

Notice: Undefined variable: content in C:\Inetpub\accounts\mm.intellstat\template.php on line 7

Which is the

echo $content;

command, taht's the odd thing.

I dunno why it's doing that.

[edited by: jatar_k at 1:36 am (utc) on July 18, 2004]
[edit reason] removed url [/edit]

ergophobe




msg:1280662
 3:44 pm on Jul 18, 2004 (gmt 0)

It looks to me like you are accessing the template directly, rather than via some other file that includes it.

At the top of your template, put the following:

if (!isset($content)) {
$content = "Content being set by template";
}

Echo_Tyme




msg:1280663
 11:55 pm on Jul 18, 2004 (gmt 0)

What if I have comment and comment2 then comment3, then i couldn't access it as easily. And the example the guy gave me was a direct access to the variable, so why can't I?

Well it reads your text, but I have the echo command underthat, it doesn't have an error, and it doesn't even recognize what the content is.

For some reason it's like the template isn't reading the page with the variables. So very odd.

Now I just re-copied what the other guy had and made other files... they work... sorta... and it's a tad more complex (realize I was just fooling around seeing if i can find the source of the error)

---Temp---

<html>
<head>
<title><?=$title?></title>
</head>
<body>
<?
include('/include/v4.php');
include('/include/4side.php');
?>

<?
echo $content;
?>

<?
include('/include/4rside.php');
include('/include/bottom.php');
?>
</body>
</html>

---End---

---Page---

<?
$content = "<p>&nbsp;&nbsp;&nbsp; Version 4 only has this one page, but you can see where i'm going with it. Below is a list of what
else you can expect from Version 4:";
$title = "Test";

include('temp.php');
?>

---End---

That oddly works, except the bottom page is showing right after the header... >.< I dunno why!? lol

---------

Ok... I just crossed my files, where the old went with the new files, worked fine both combinations, but them back to how they work, still fine... then on the old files I changed the title... error on $content again... When it did work when I loaded it b4 the title change the title still read that there was an error... yet it loaded.... it's odd...

[edited by: jatar_k at 4:29 pm (utc) on July 19, 2004]
[edit reason] removed urls [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved