beginner question

Reply

Join Date: Sep 2007
Posts: 10
Reputation: sethbaur is an unknown quantity at this point 
Solved Threads: 0
sethbaur sethbaur is offline Offline
Newbie Poster

beginner question

 
0
  #1
Dec 16th, 2007
Hey I'm a php beginner and I'm having some problems with the website I'm testing with. I'll show you first the relevant code.

index.php:
  1. <?php
  2. include "stdlib.php";
  3. $page = new Page();
  4. $page->title = "Index";
  5. $page->printHeader();
  6. ?>
  7. <style type="text/css">
  8. div.container
  9. {
  10. width:100%;
  11. margin:0px;
  12. border:1px solid gray;
  13. }
  14. div.left
  15. {
  16. width:100px;
  17. float:left;
  18. padding:1em;
  19. margin:0;
  20. }
  21. div.content
  22. {
  23. margin-left:190px;
  24. border-left:1px solid gray;
  25. padding:1em;
  26. }
  27. </style>
  28. <div class="container">
  29. <div class="left"><p class="left">Seth Baur</p></div>
  30. <div class="content">
  31. <p>Welcome to my site.</p>
  32. <?php echo date("d-m-Y"); ?>
  33. <form action="form.php" method="post">
  34. Name: <input type="text" name="name" /><br />
  35. Age: <input type="text" name="age" /><br />
  36. <input type="submit" />
  37. </form>
  38. </div>
  39. </div>
  40. <?php
  41. $page->printFooter();
  42. ?>

stdlib.php:
  1. <?php
  2. function __autoload($class_name){
  3. require_once $class_name . '.php';
  4. }
  5. ?>

Page.php:
  1. <?php
  2. class Page {
  3. var $title;
  4. function printHeader() {
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  10. <link rel="stylesheet" type="text/css" href="styles.css" />
  11. <title><?php echo $this->title; ?></title>
  12. </head>
  13. <body>
  14. <?php
  15. }
  16. function printFooter() {
  17. ?>
  18. </body>
  19. </html>
  20. <?php
  21. }
  22. }
  23. ?>

The error I'm getting now that I've put in the autoload function is:
  1. Fatal error: Cannot instantiate non-existent class: page in /home/content/t/h/r/threepio/html/seth/php/index.php on line 3

All of these files are in the same directory, so I'm not sure why it can't find the Page class. Anyone have an idea?
Last edited by sethbaur; Dec 16th, 2007 at 10:08 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: beginner question

 
0
  #2
Dec 16th, 2007
Where is the variable $class_name coming from and how is it populated? On line 3 of index.php, you have $page = new Page(); but, you never defined the class Page() in stdlib.php. I see you did it on Page.php but this will only have a local scope of the page its defined in.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 7
Reputation: MickRip is an unknown quantity at this point 
Solved Threads: 3
MickRip's Avatar
MickRip MickRip is offline Offline
Newbie Poster

Re: beginner question

 
0
  #3
Dec 16th, 2007
For interests sake, what happens when you replace:
include"stdlib.php";
with
include "Page.php"; ?

Try transforming Page into lowercase as well..
Last edited by MickRip; Dec 16th, 2007 at 11:48 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 10
Reputation: sethbaur is an unknown quantity at this point 
Solved Threads: 0
sethbaur sethbaur is offline Offline
Newbie Poster

Re: beginner question

 
0
  #4
Dec 17th, 2007
buddylee17:
The variable $class_name is passed to the autoload function when the it comes to a class that is not defined. At that point it includes the class it couldn't find with ".php" appended on the end.

MickRip:
And yes I could replace stdlib.php with Page.php, but the idea is that this way, I could include many classes, in individual files, without "including" each.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC