Jump to content


Photo

PHP classes


  • Please log in to reply
7 replies to this topic

#1 kamasheto

kamasheto
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 21 October 2006 - 06:04 PM

<?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>";		
	}
}
?>

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 October 2006 - 06:14 PM

That should work in both PHP4 and 5.

Whats the problem?

#3 kamasheto

kamasheto
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 21 October 2006 - 06:22 PM

I'm getting a blank screen, with no html code whatsover!

here's a screenshot >> http://img326.images...ntitled1hn1.jpg

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 October 2006 - 06:25 PM

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:
// call the CFS class
$cfs = new CFS;


#5 kamasheto

kamasheto
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 21 October 2006 - 06:32 PM

<?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;
?>
This works just fine, thank you :)

#6 kamasheto

kamasheto
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 21 October 2006 - 08:25 PM

class CFS {
	var $version = "v1.0";
	function CFS()
	{
		switch($_GET['do'])
		{
			default:
			$this->showlogin();
			break;
			case "login":
			$this->login();
			break;
		}	
	}
	function showlogin()
	{
	}
	function login()
	{
	}
}

I'm getting this error

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

#7 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 October 2006 - 08:33 PM

you switch statement is out of whack. you must put all your options before 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:
<?php
if (isset($_GET['do'])) {
  switch($_GET['do']) {
    case 'login':
      $this->login();
      break;

    default:
      $this->showlogin();
  }
}
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#8 kamasheto

kamasheto
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 21 October 2006 - 08:47 PM

else { $this->showlogin(); }

works perfectly this way ;) thank you




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users