Получить заголовок, соответствующий заголовку ссылки - PullRequest
0 голосов
/ 10 марта 2009

Я занимаюсь разработкой сайта, похожего на Digg, и хочу, чтобы заголовок страницы комментариев соответствовал заголовку ссылки, здесь указан код файла комментариев:

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);
        }

Я понимаю, что должен изменить "$ this-> setTitle ($ title);" для чего-то с этим: $ article-> getTitle (); но я пробовал разные вещи и просто показывает ошибки.

Я думаю, что я не был достаточно ясен: заголовок в верхней части страницы должен измениться и совпадать с заголовком новости на этой странице (это сайт: kiubbo.com) Thx

Ответы [ 2 ]

2 голосов
/ 10 марта 2009

Как насчет этого:

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);
    }
}
1 голос
/ 10 марта 2009

Я немного растерялся. Вы просто ищете собственность добытчика / установщика?

<?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);
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...