Hello ZF users,
I am currently building a new ZF site in a sandbox directory (example.com/sandbox/mysite) and I'm curious as to how many of you are creating URLs to non-ZF files like images, stylesheets, etc.
I understand that when I visit /sandbox/mysite/somecontroller/someaction, my browser "thinks" I'm actually in a directory called "someaction". Therefore, simple relative URLs do not work:
<img src="images/logo.png" alt="" /> <-- firebug says my browser requested "http://example.com/sandbox/mysite/somecontroller/someaction/images/logo.png" which does not exist.
In my view scripts, I am currently using a global constant DOC_ROOT that is dynamically defined based on dirname($_SERVER['PHP_SELF']), which resolves to "/sandbox/mysite":
<img src="<?= DOC_ROOT ?>/images/logo.png" alt="" /> <-- works
However, I feel that that looks a little clumsy, especially next to links that use the url() view helper (which automatically prepends the correct relative path prefix).
Is there a better way to easily create relative URLs that are not based on routes? I want to avoid using <base href="" /> if possible. Thanks!
-Hector
2008年12月30日星期二
订阅:
博文评论 (Atom)
没有评论:
发表评论