tags:

views:

117

answers:

3

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

+2  A: 

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.

cdmckay
+1  A: 

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?

royatl
+1  A: 

In showAllComments() maybe you could do

UI::setTitle($article->getTitle());
Tom Haigh
I have try it but does not work. Probably the header is build before the showAllComments function.
Slzr
yeah that makes sense. Maybe showAllComments() could take an instance of Article rather than article_id , then you can fetch it outside the function and before outputting any HTML
Tom Haigh