views:

80

answers:

2

I am a bit lost here, solution could be lurking under my nose but I couldn't get, thought of you guys if any one can help.

Here is the problem: I have Zend Framework standard file layout:

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

Now The problem is, I am referencing images in layouts.phtml by just images/logo.gif etc. and same in the controller views /images/arrow.gif

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

but if the request is more deep like http://servername/project/controller/index/page/2

the images break theirselves, they clearly can't get the path, what I am noticing is, if I am on later request, the image path will be http://servername/project/controller/index/page/2/images/logo.gif which is not there, the image is in public/images

My understanding was (and I have googled it a bit as well) framework knows the default public and will route the images to public/images always. However, this is not working. Do I have to add some re-write rule or something?

Can anyone help please? I will be grateful!

+3  A: 

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

Here is the solution:

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

Edit after further investigation

For record and to help others: You can access images folder in public as you normally would in non Zend framework environment if you have configured your DocumentRoot properly. I only made a virtual directory in my httpdconf while if you do not create a VirtualHost and do not give DocumentRoot to it while your files are also not in default htdocs directory, expect this problem. See Create a Virtual Host heading in following URL: http://framework.zend.com/manual/en/learning.quickstart.create-project.html and that will solve the problem!

Hammad Tariq
It's ok to accept your own answers :)
chelmertz
A: 

Just put a slash in front of your path. So instead of

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

Try

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

Without the slash it will append the path to the relative path as you discovered. Hammad solution should work too since it will generate the right code but now you know why you had problems.

Iznogood
is there a configuration for this? because I have checked the way you are suggesting, its not working, more over if I ask the firefox to just 'View Image' it takes me to http://localhost/images/blah.gif while I have a project folder in localhost in which images folder is under public directory. Any thoughts?
Hammad Tariq
@Hammad I tought you had fixed your problem? And no other configuration then having /images withthe right permissions and in your websites public folder. If it doesnt work somethnig mightbe wrongwith your htaccess or permissions or I am not seeing something obvious.
Iznogood
@iznogood yes it worked but as you are suggesting that is more of a work around if zend should get images folder by itself, the problem now is, I have created a zend form in /library/forms/blah/blah.php and I have tried giving it every possible combination to get to the images folder (because I am trying to get a button element with image) but that is not working. baseUrl is also not available in zend form, any suggestions?
Hammad Tariq
@Hammad. It doesnt matherwhereyour codeis. Imageswill always be relative to the public folder. You should probably post a new question about that since you accepted your own answer that does not work for you.
Iznogood