非常に厄介な問題で、バグの原因を突き止めるために非常に長い調査を行いました。このために元の投稿を作成しましたが、新しい投稿を作成するために削除しました。それでは、最初から始めましょう。最後までお読みいただき、誠にありがとうございます。
ViewHelperPub.phpがあります。これはランダムに広告を表示します。$ this-> pub()は、layout.phtmlおよびphtmlビューファイルで呼び出されます。ヘルパーは、表示する前にインプレッション数も増やします。
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;
}
増加印刷()
public function increasePrint($id){
$table = $this->getTable();
$row = $table->find($id)->current();
$row->imp_made = $row->imp_made + 1;
return $row->save();
}
私のlayout.phtmlもシンプルです:
<html>
<head>
<?= $this->pub(null, 'css') ?>
</head>
<body>
<?= $this->pub(null, 'big_banner' ?>
</body>
問題:一部のアクションでは、レイアウト内の広告が選択され、2回インクリメントされます!まるでヘルパーが再びインスタンス化されたかのように。
いくつか検索した後、問題は別のView Helper:LogoEventから発生しているようです。このヘルパーは、適切なHTMLコードを返すことによってロゴ/画像を表示します。
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" />';
}
}
}
二重インクリメントは、ファイルがハードディスクに存在しない場合に発生します。本当に奇妙な...私はこれを試しました:
echo $this->logoEvent( 'existing_image.jpg', '100');
// No problem, everything works fine.
echo $this->logoEvent( 'unexisting_image.jpg', '100');
// => problem.
だが
echo htmlentities($this->logoEvent( 'unexisting_image.jpg', '100'));
// No problem, everything works fine.
誰かが私よりも良い知識を持っていて、何が問題であるか、またはそれを見つける方法を見つけることができます...ありがとう!