kamasheto Posted October 21, 2006 Share Posted October 21, 2006 [code]<?phpclass 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 Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/ Share on other sites More sharing options...
wildteen88 Posted October 21, 2006 Share Posted October 21, 2006 That should work in both PHP4 and 5.Whats the problem? Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/#findComment-112375 Share on other sites More sharing options...
kamasheto Posted October 21, 2006 Author Share Posted October 21, 2006 I'm getting a blank screen, with no html code whatsover!here's a screenshot >> http://img326.imageshack.us/img326/1931/untitled1hn1.jpg Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/#findComment-112378 Share on other sites More sharing options...
wildteen88 Posted October 21, 2006 Share Posted October 21, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/#findComment-112380 Share on other sites More sharing options...
kamasheto Posted October 21, 2006 Author Share Posted October 21, 2006 [code]<?phpclass 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/#findComment-112384 Share on other sites More sharing options...
kamasheto Posted October 21, 2006 Author Share Posted October 21, 2006 [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 errorNotice: Undefined index: do in C:\wamp\www\CFSII\index.php on line 21Line 21: switch($_GET['do']) Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/#findComment-112438 Share on other sites More sharing options...
obsidian Posted October 21, 2006 Share Posted October 21, 2006 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]<?phpif (isset($_GET['do'])) { switch($_GET['do']) { case 'login': $this->login(); break; default: $this->showlogin(); }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/#findComment-112442 Share on other sites More sharing options...
kamasheto Posted October 21, 2006 Author Share Posted October 21, 2006 else { $this->showlogin(); }works perfectly this way ;) thank you Quote Link to comment https://forums.phpfreaks.com/topic/24674-php-classes/#findComment-112450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.