Just started practicing classes and boom my first try cant get it to work ... maybe im not seeing something ... can someone look and point out the thing that i might have misssed .. ?any help would be appreciated .. thanx

here's the code :

index.php

<?
include "page.class.php";

$clan911 = new page;

$data = "<p>Clan 911 </p>";

$clan911->title = 'Clan 911';
$clan911->keywords = 'CLAN 911';
$clan911->setcontent($data);

$clan911->display();
?>

page.class.php

<?
class page
{
    var $title;
    var $keywords;
    var $content;

    function display()
    {
        echo "<html>\n<head>";
        $this->displaykeywords();
        $this->displaytitle();
        echo "</head>\n<body>";
        $this->content;
        echo '</body>';
        echo '</html>';


    }

    function displaytitle()
    {
        echo '<title>' . $this->title . "</title>\n";
    }

    function displaykeywords()
    {
        echo '<meta name="keywords" content="' . $this->title . '">';
    }

    function setcontent($data)
    {
        $this->content = $data;
        //echo $data;
    }
}


?>

It doesnt print out the content.. somehow the function, i think, is not getting the data sent by $clan911->setcontent($data);

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Try this.

//php.class.php
<?php
class page
{
var $title;
var $keywords;
var $content;

function display()
{
$x="<html>\n<head>";
$x.=$this->displaykeywords();
$x.=$this->displaytitle();
$x.="</head>\n<body>";
$x.=$this->content;
$x.='</body>';
$x.='</html>';
return $x;

}

function displaytitle()
{
echo '<title>' . $this->title . "</title>\n";
}

function displaykeywords()
{
echo '<meta name="keywords" content="' . $this->title . '">';
}

function setcontent($data)
{
$this->content = $data;
//echo $data;
}
}
?>

And this is index.php

<?php
include "page.class.php";

$clan911 = new page();

$data = "<p>Clan 911 </p>";

$clan911->title = 'Clan 911';
$clan911->keywords = 'CLAN 911';
$clan911->setcontent($data);

$contents = $clan911->display();
echo $contents;
?>

Try this.

//php.class.php
<?php
class page
{
var $title;
var $keywords;
var $content;

function display()
{
$x="<html>\n<head>";
$x.=$this->displaykeywords();
$x.=$this->displaytitle();
$x.="</head>\n<body>";
$x.=$this->content;
$x.='</body>';
$x.='</html>';
return $x;

}

function displaytitle()
{
echo '<title>' . $this->title . "</title>\n";
}

function displaykeywords()
{
echo '<meta name="keywords" content="' . $this->title . '">';
}

function setcontent($data)
{
$this->content = $data;
//echo $data;
}
}
?>

And this is index.php

<?php
include "page.class.php";

$clan911 = new page();

$data = "<p>Clan 911 </p>";

$clan911->title = 'Clan 911';
$clan911->keywords = 'CLAN 911';
$clan911->setcontent($data);

$contents = $clan911->display();
echo $contents;
?>

Works Thanx Alot

This article has been dead for over six months. Start a new discussion instead.