Joomla framework calls View display function 3 times

This forum is for general questions about extensions for Joomla! 2.5.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
Robert JForum
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Jan 28, 2011 2:04 pm

Joomla framework calls View display function 3 times

Post by Robert JForum » Fri Jan 28, 2011 2:16 pm

I have built a custom Joomla 1.6 component (MVC) with a standard display function in view.html.php like this:
// Overwriting JView display method
function display($tpl = null)
{
// Assign data to the view
$this->Content = $this->get('Content');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Display the view
parent::display($tpl);
}

Problem is that this function is called 3 times for each page that has my component.
You can reproduce this behavior by adding a line like this:

$fp=fopen("/var/www/site/log.html","a");fwrite($fp,"<pre>".print_r(time(),true)."</pre>");fclose($fp);

Is this a bug in 1.6? Is it by design? How can i distinguish between the 3 calls and only run the required code once?

Regards, Robert

 
jtanmay
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Thu Feb 04, 2010 6:15 pm
Contact:

Re: Joomla framework calls View display function 3 times

Post by jtanmay » Fri Feb 04, 2011 3:12 pm

Hi Robert,

Not sure what problem you are having! but below is my code for my component com_rules

Code: Select all

class RulesViewRules extends JView {

    // Overwriting JView display method
    function display($tpl = null) {
        error_log(time());
        // Assign data to the view
        $this->article = $this->get('Article');
        if (count($errors = $this->get('Errors'))) {
            JError::raiseError(500, implode('<br/>', $errors));
            return false;
        }
        // Display the view
        parent::display($tpl);
    }

}
and looking at the logs, it seems its calling it once.
and you dont need to open and close a file just for logging things! use error_log functionality!

May be you can try tracing your calls, may be try using Xdebug to see what calls are been made when you load your page.

And may be some expert will soon comment on this for you!.

Thanks
Tanmay

 

Locked

Return to “Extensions for Joomla! 2.5”