0

Very nasty problem, I made a very long investigation to find out what was the origin of the bug. I made an original post for this, but I deleted it to create a new fresh post. So let's start by the start. Thank you in advance for reading this until the end.

I have a View Helper Pub.php. This one display randomly an ad. $this->pub() is called in the layout.phtml and in the phtml view files. The Helper also increments the number of impression before displaying it.

Pub.php

Class My_View_Helper_Pub extends Zend_View_Helper_Abstract {

public function pub( $place, $format ) {
    // Extract the active campaigns, then randomly select one
    $campaigns = $model->getActiveCampaigns();
    ...
    // Increase the number of view for this campaign (in MySQL)
    $model->increasePrint($campaign->id);

    // And display the banner
    echo $this->generateHtml($campaign->filename);

}

public function generateHtml($filename){
    // Generate the html according to the filename (image, flash, custom tag etc...)
    return $code;
}

IncreasePrint()

public function increasePrint($id){

    $table = $this->getTable();

    $row = $table->find($id)->current();
    $row->imp_made = $row->imp_made + 1;

    return $row->save();
}

My layout.phtml is also simple :

<html>
<head>
   <?= $this->pub(null, 'css') ?>
</head>
<body>
   <?= $this->pub(null, 'big_banner' ?>
</body>

Problem : On some actions, ads in the layout are selectionned and incremented twice ! As if the helper was instancied again.

After some search, the problem seems to come from another View Helper : LogoEvent. This helper displays a logo/image by returning proper HTML code.

LogoEvent.php

class My_View_Helper_LogoEvent extends Zend_View_Helper_Abstract
{
    public function logoEvent($image, $taille = null){
        $image = trim($image);

        if ($taille){
            $width = "max-width: {$taille}px;";
    } else {
        $width = '';
    }

    if (!empty($image)){

        return '<img src="/images/agenda/logos/'. $image .'" style="'. $width .'" alt="Logo" />';

    } else {

        return '<img src="/images/agenda/logos/no-logo.png" style="'. $width .'" alt="No Logo" />';

    }
}

}

The double-incrementation happens when the file doesn't exist on my hard disk. Really weird... I tried this :

echo $this->logoEvent( 'existing_image.jpg', '100');
// No problem, everything works fine.

echo $this->logoEvent( 'unexisting_image.jpg', '100');
// => problem.

But

 echo htmlentities($this->logoEvent( 'unexisting_image.jpg', '100'));
 // No problem, everything works fine.

Someone has better knowledge than me to find out what could be the problem or a way to find it... Thank you !

  • 1
    If you open /images/agenda/logos/unexisting_image.jpg in a browser - are there ads on that page (i.e. your 404/error page)? As that would explain the double increment. – Tim Fountain Dec 02 '11 at 19:51
  • Effectively, according as I'm logged or not, i'll get the login page or the index page. With the ads on the layout displayed again ! – Supertino7 Dec 05 '11 at 09:57

1 Answers1

0

I'm almost certain that your problem is from .htaccess, where, be default in ZF, is set to send all non-existing files (the -s condition) to index.php, thus your application will fire up again (possibly into the ErrorController, for 404).

Add this in .htaccess instead, see how it fits (it omits certain files to be routed to index.php):
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]

nevvermind
  • 3,302
  • 1
  • 36
  • 45
  • As I replied to Tim Fountain, you're right the problem seems to come from this point, when I open an unexisting image in the browser, I'm redirected onto the index page (or login page) with layout ads displayed. I added your line before or after "RewriteRule ^.*$ index.php [NC,L]" but it didn't fix the problem, I'm still redirected to the application – Supertino7 Dec 05 '11 at 10:03
  • Replaced the original line "RewriteRule ^.*$ index.php [NC,L]" by your. It seems to work. But will it work everywhere else ? – Supertino7 Dec 05 '11 at 10:17