Php 视图\u辅助对象中未找到图像导致另一个视图\u辅助对象中出现多个db查询

Php 视图\u辅助对象中未找到图像导致另一个视图\u辅助对象中出现多个db查询,php,zend-framework,zend-view,view-helpers,viewhelper,Php,Zend Framework,Zend View,View Helpers,Viewhelper,这是一个非常棘手的问题,我做了很长时间的调查,以找出错误的根源。我为此写了一篇原创文章,但我删除了它以创建一篇新文章。让我们从头开始。提前感谢您阅读本文,直到最后 我有一个视图助手Pub.php。这一个随机显示广告。在layout.phtml和phtml视图文件中调用$This->pub()。辅助对象还会在显示印象之前增加印象的数量 Pub.php Class My_View_Helper_Pub extends Zend_View_Helper_Abstract { public funct

这是一个非常棘手的问题,我做了很长时间的调查,以找出错误的根源。我为此写了一篇原创文章,但我删除了它以创建一篇新文章。让我们从头开始。提前感谢您阅读本文,直到最后

我有一个视图助手Pub.php。这一个随机显示广告。在layout.phtml和phtml视图文件中调用$This->pub()。辅助对象还会在显示印象之前增加印象的数量

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;
}
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" />';

    }
}
增加打印()

我的布局。phtml也很简单:

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

有人比我更了解如何找出问题或找到问题的方法。。。
谢谢大家!

我几乎可以肯定您的问题来自.htaccess,在ZF中默认设置为将所有不存在的文件(
-s
条件)发送到index.php,因此您的应用程序将再次启动(可能会进入ErrorController,例如404)

改为将其添加到.htaccess中,看看它是否合适(它省略了某些要路由到index.php的文件):

重写规则!\。(js | ico | gif | jpg | png | css)$index.php[NC,L]

如果在浏览器中打开/images/agenda/logos/unexisting|image.jpg,该页面(即404/error页面)上是否有广告?这可以解释双增量。实际上,根据我是否登录,我将获得登录页面或索引页面。再次显示版面上的广告!正如我对Tim Fountain的回答,你是对的,问题似乎来自这一点,当我在浏览器中打开一个不存在的图像时,我会被重定向到索引页面(或登录页面),并显示布局广告。我在“RewriteRule^.*$index.php[NC,L]”之前或之后添加了您的行,但它并没有解决问题,我仍然被重定向到应用程序,并将原来的行“RewriteRule^.*$index.php[NC,L]”替换为您的。它似乎起作用了。但它会在其他地方起作用吗?
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.