Jump to content

Archived

This topic is now archived and is closed to further replies.

kamasheto

PHP classes

Recommended Posts

[code]<?php
class CFS {
function CFS()
{
$this->html_head();
$this->html_body();
$this->html_footer();
}
function html_head()
{
print "<html>
<body>";
}
function html_body()
{
print "testing the body message";
}
function html_footer()
{
print "</body>
</html>";
}
}
?>[/code]

I was wondering why this ain't working. Does it matter if I have php5 or php4? (I'm using php5.1.6) and what should I do to the above to make it work with the version I have.

Thanks

Share this post


Link to post
Share on other sites
I'm getting a blank screen, with no html code whatsover!

here's a screenshot >> http://img326.imageshack.us/img326/1931/untitled1hn1.jpg

Share this post


Link to post
Share on other sites
Right click and select View Source form the context menu. What do you get? Is that blank too?

If it is then I would recommend you to turn on display_errors and turn error_reporting to E_ALL in the php.ini. When you made the changes restart the server and run the script again. This time if there is any errors PHP will display them.

However i have ran your code and it works fine. Make sure you are initiating you class. To initiate the class add the following code after you defind the CFS class:
[code=php:0]// call the CFS class
$cfs = new CFS;[/code]

Share this post


Link to post
Share on other sites
[code]<?php
class CFS {
function CFS()
{
$this->html_head();
$this->html_body();
$this->html_footer();
}
function html_head()
{
print "<html>
<body>";
}
function html_body()
{
print "testing the body message";
}
function html_footer()
{
print "</body>
</html>";
}
}
$cfs = new CFS;
?>[/code]
This works just fine, thank you :)

Share this post


Link to post
Share on other sites
[code]class CFS {
var $version = "v1.0";
function CFS()
{
switch($_GET['do'])
{
default:
$this->showlogin();
break;
case "login":
$this->login();
break;
}
}
function showlogin()
{
}
function login()
{
}
}[/code]

I'm getting this error

Notice: Undefined index: do in C:\wamp\www\CFSII\index.php on line 21
Line 21: switch($_GET['do'])

Share this post


Link to post
Share on other sites
you switch statement is out of whack. you [b]must[/b] put all your options [i]before[/i] your default. don't know if this is causing your issue, since i don't know where you're referencing "index.php" in your code, but your switch ought to look more like this:
[code]
<?php
if (isset($_GET['do'])) {
  switch($_GET['do']) {
    case 'login':
      $this->login();
      break;

    default:
      $this->showlogin();
  }
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.