2009年5月6日星期三

[fw-mvc] Head* view helpers and baseUrl

Would it be possible to make the Head* view helpers baseUrl-aware like the url() view helper for relative paths? I currently have my ZF application installed in a subdirectory which is breaking relative urls for css and js files.

For example:

<?= $this->headLink()->appendStylesheet('css/styles.css') ?>

Results in:

<link href="css/default.css" media="screen" rel="stylesheet" type="text/css" />
When I'm on the homepage of my site at http://www.example.com/~hvirgen/myzfapp, the CSS file can be read because the relative path maps to its physical location.

But when I start navigating into the site it throws off my relative paths:

css relative path: css/style.css

If my ZF application was in the webroot, then it would be perfectly fine to prepend all the paths with a forward-slash (/css/style.css), but my project is going to be deployed in a subdirectory that is different than my development directory (as in, it won't be /~hvirgen/myzfapp when we go live).

One suggestion I was given a while back was to create a baseUrl view helper, but it is becoming tedious and repetitive to wrap all of my relative urls in that helper.

-Hector

没有评论: