jcslzr
jcslzr

Reputation: 435

Dynamic page Titles

I have this class for page titles:

class UI {

    private static $title;

    public static function getTitle() { return self::$title; }
    public static function setTitle($value) { self::$title = $value; }
    }

So in my frontpage I simple declare this:

UI::setTitle('Kiubbo.com :: Todas las Noticias, Fotos y Videos');

And works fine. The problem is to get the comments pages titles to change depending on the content (title of links). I want to be the same as this variable (that has the same name but it its for another function its not the same getTitle):

<?php echo $article->getTitle(); ?>

Which its in this function:

function showAllComments($article_id, $param)
    {

        $article = Article::getById($article_id);

        if(!empty($article))
        {
            ?>
            <div class="news_item">
                <h2 class="news_item_title"><b><a href = "<?php echo $article->getUrl(); ?>"><?php echo $article->getTitle(); ?></a></b></h2>              

            </div>

If anyone can help I appreciate it.

Thx

Upvotes: 0

Views: 246

Answers (3)

Tom Haigh
Tom Haigh

Reputation: 57845

In showAllComments() maybe you could do

UI::setTitle($article->getTitle());

Upvotes: 1

royatl
royatl

Reputation: 336

change " $article->getTitle() " to " UI::getTitle() " and it should work, but I don't think that is what you really want to do, is it?

Upvotes: 1

cdmckay
cdmckay

Reputation: 32290

I'm not sure I completely understand what you want to do. If you want each object to have a separate title, then you need to make the title variable non-static (and the functions non-static as well). A static variable/function has only one instance per class.

Upvotes: 4

Related Questions