CHtml::image(); issue

I’m not pretty sure if that’s an issue, but after some investigation related with this topic, here is reproduction of the “defect”:

  • Download latest Yii release (1.6).

  • go to /demos/blog and

    • edit /protected/views/layouts/main.php with adding these two lines:


$_SESSION['cn'] = ($_SESSION['cn']+1);

echo $_SESSION['cn']; 


  • edit /protected/views/layouts/column2.php with adding these line:


echo CHtml::image("test.jpg");


As a result from this, open blog home page and make couple of impressions and see that $_SESSION[‘cn’] increments with 1.

Now navigate to "Welcome!" link.

See incrementing of $_SESSION[‘cn’] when refresh this page.

In my test, it increments with 2.

I’m not sure where is the problem, but in my Yii powered site this looks pretty f***d up, coz one of my sitewide methods are called >10 times per impression. :D

I hope someone to confirm this and to say is this really an issue.


If you are here

and within that page you do:

echo CHtml::image("test.jpg");

then the browser will try to read the image from:

See the problem?

You should make sure all resources you include into html are available. Otherwise the browser may request the page once more internally (due to htaccess rewrite).

I guess somewhere in your application you try to include an image (maybe via css?) that does not exist.