Jump to content

PHP classes


kamasheto

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
Link to comment
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]
Link to comment
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 :)
Link to comment
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'])
Link to comment
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]
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.