[Catalyst] Link to file

Peter Karman peter at peknet.com
Thu May 24 17:09:42 GMT 2007



Will Smith wrote on 5/24/07 10:43 AM:
> the error is : File Not Found. Yes, I have apache, and also tried on dev
> machine at localhost. Problem is when adding the file path to template, like:
> <a href="[% myvar %]">listen</a>, and myvar =
> '/var/www/html/myfolder/myfile.wav'; when move the cursor over  "listen" the
> link is : http://localhost:3000/var/www/html/myfolder/myfile.wav  or
> http://www.mydomain.com/var/www/html/myfolder/myfile.wav
> 
> Obviously, this is the wrong path to the file. How can I drop the http://...
> before the real path? Thank you

Your browser is assuming the http:// scheme since href value is relative.

If you want to serve via local fs, then you probably want file:// instead.

if you want to serve the .wav via http, you need the http:// scheme on there,
and you'll want to come up with a structure for serving static content that 
doesn't use your Cat app directly. The way I do it is to have all my static 
content served under a separate apache vhost, and then in my Cat code, set that 
static url base in my config. So my .tt files look like:

  <a href="[% page.static %]/thing/I/want/to/serve">thing</a>

The Static::Simple plugin lets you serve static content from Cat itself, but 
that's intended for devel only since tying up Cat time with static content is 
considered Not a Best Practice. So I just avoid it altogether and run a separate 
apache process on my dev box that serves my static content for me. That way 
moving from dev to production is as simple as changing the config definition for 
[% page.static %].


-- 
Peter Karman  .  http://peknet.com/  .  peter at peknet.com



More information about the Catalyst mailing list