tags:

views:

162

answers:

2

I am developing a Digg like site and I want the title of the comments page to match the link title, here its the comments file code:

class CommentsPage extends Page {

    function __construct($title = '')
    {
        $this->setTitle($title);
    }

    function header()
    {
        parent::header();
    }

    function showAllComments($article_id, $param)
    {


        $article = Article::getById($article_id);
        if(!empty($article))
        {
            ?>
            <div class="news_item">
                <a href="/index.php?action=vote&param=<?php echo $article->getId(); ?>"><img alt="vote button" class="vote_button" height="10" src="assets/images/vote2.png" width="10" class="border_less" /></a>
                <h2 class="news_item_title"><b><a href = "<?php echo $article->getUrl(); ?>"><?php echo $article->getTitle(); ?></a></b></h2>
                <span class="news_item_url">(<?php echo $article->getUrlDomain(); ?>)</span>
                <div class="news_item_info"><?php $points = $article->getPoints(); echo $points > 1 ? "$points points" : "$points point"; ?> by <a href="/index.php?action=user&param=<?php echo $article->getUsername(); ?>"><?php echo $article->getUsername(); ?></a> <?php echo $article->getElapsedDateTime(); ?></div>
                <p class="news_item_content"><?php echo $article->getDescription(); ?></p>
            </div>
            <?php
            $this->showSubmitForm($article);
        }

I understand I have to change "$this->setTitle($title);" for something with this: $article->getTitle(); but I have tried different things and just shows errors.

I think I was not clear enough: the title on top of the page to change and be the same as the news item title for that page (this is the site: kiubbo.com) Thx

+1  A: 

I'm a bit confused. Are you just looking for a property getter/setter?

<?php
class CommentsPage extends Page {

    protected $title;

    function __construct($title = '')
    {
        $this->setTitle($title);
    }

    //  This function does nothing, by the way
    function header()
    {
        parent::header();
    }

    public function setTitle( $title )
    {
        $this->title = $title;
    }

    public function getTitle()
    {
        return $this->title;
    }

    function showAllComments($article_id, $param)
    {


        $article = Article::getById($article_id);
        if(!empty($article))
        {
            ?>
            <div class="news_item">
                <a href="/index.php?action=vote&param=<?php echo $article->getId(); ?>"><img alt="vote button" class="vote_button" height="10" src="assets/images/vote2.png" width="10" class="border_less" /></a>
                <h2 class="news_item_title"><b><a href = "<?php echo $article->getUrl(); ?>"><?php echo $this->getTitle(); ?></a></b></h2>
                <span class="news_item_url">(<?php echo $article->getUrlDomain(); ?>)</span>
                <div class="news_item_info"><?php $points = $article->getPoints(); echo $points > 1 ? "$points points" : "$points point"; ?> by <a href="/index.php?action=user&param=<?php echo $article->getUsername(); ?>"><?php echo $article->getUsername(); ?></a> <?php echo $article->getElapsedDateTime(); ?></div>
                <p class="news_item_content"><?php echo $article->getDescription(); ?></p>
            </div>
            <?php
            $this->showSubmitForm($article);
        }
    }
}
Peter Bailey
Thanks for answering. What I want is to have the the title page the same as the news item article title.Thank you for the header function correction, someone did this for me and I am trying to fix it.
Slzr
I think I was not clear enough: the title on top of the page to change and be the same as the news item title for that page (this is the site: kiubbo.com) Thx
Slzr
If I understand you right, that will involve changing the HTML page's title. The HTML for that is not included with the code snippet you provided - so it's currently impossible for me to tell you where to change it at.
Peter Bailey
+2  A: 

How about this:

class CommentsPage extends Page
{
    private $article;

    function __construct($article_id)
    {
        $this->article = Article::getById($article_id);
        if(!empty($article))
        {
            $this->setTitle($article->getTitle());
        }
        else
        {
            //Throw an exception
        }
    }

    function header()
    {
        parent::header();
    }

    function showAllComments($param)
    {
        if(!empty($this->article))
        {
        ?>
            <div class="news_item">
                <a href="/index.php?action=vote&param=<?php echo $this->article->getId(); ?>"><img alt="vote button" class="vote_button" height="10" src="assets/images/vote2.png" width="10" class="border_less" /></a>
                <h2 class="news_item_title"><b><a href = "<?php echo $this->article->getUrl(); ?>"><?php echo $this->article->getTitle(); ?></a></b></h2>
                <span class="news_item_url">(<?php echo $this->article->getUrlDomain(); ?>)</span>
                <div class="news_item_info"><?php $points = $this->article->getPoints(); echo $points > 1 ? "$points points" : "$points point"; ?> by <a href="/index.php?action=user&param=<?php echo $this->article->getUsername(); ?>"><?php echo $this->article->getUsername(); ?></a> <?php echo $this->article->getElapsedDateTime(); ?></div>
                <p class="news_item_content"><?php echo $this->article->getDescription(); ?></p>
            </div>
        <?php
        $this->showSubmitForm($this->article);
    }
}
I tried but did not work thx anyway
Slzr