Images in the Zend Framework Layout

I got a little lost here, the solution may be hiding under my nose, but I could not get it, I thought about you guys if someone can help.

Here is the problem: I have a standard Zend Framework file format:

Project -application -controllers -views -layouts -scripts -layouts.phtml -library -public -images -index.php 

Now the problem is that I only refer to images in layouts.phtml with images / logos, etc., and the same thing in controller views /images/arrow.gif

This works fine if the request is simple http: // servername / project / controller

but if the request is deeper, like http: // servername / project / controller / index / page / 2

images break, they obviously cannot get the path, which I notice, if I am on a later request, the image path will be http: //servername/project/controller/index/page/2/images/logo.gif , which is not, image open / images

My understanding was (and I was also looking for it a bit), the infrastructure knows the default publication and will always direct images to public / images. However, this does not work. Should I add a rewrite rule or something else?

Can anyone help? I will be grateful!

+4
source share
2 answers

Sometimes you need to first ask the person sitting next to you!

Here is the solution:

 <?=$this->baseUrl('images/logo.gif')?> 

Change after further research

To record and to help others: you can access the folder with images publicly, as usual, in an environment without Zend, if you have correctly configured your DocumentRoot. I just created a virtual directory in my httpdconf, and if you do not create VirtualHost and provide DocumentRoot until your files are also in the default htdocs directory, expect this problem. See Create a virtual host header at the following URL: http://framework.zend.com/manual/en/learning.quickstart.create-project.html and this will solve the problem!

+10
source

Just put a slash in front of your path. Therefore, instead of

 <img src="images/logo.gif" /> 

Try

 <img src="/images/logo.gif" /> 

Without a slash, it will add the path to the relative path that you found. The Hammad solution should work as well, since it generates the correct code, but now you know why you had problems.

+4
source

All Articles