Reputation: 3613
Is there a way to get CakePHP's css method to emit a path relative to the current document?
I.e., using this code:
$this->Html->css('tutorial');
Instead of generating
<link rel="stylesheet" type="text/css" href="/Tutorial/css/tutorial.css" />
it would instead generate something like
<link rel="stylesheet" type="text/css" href="../../css/tutorial.css" />
I know this is goofy, but I'm looking to create something that can be retrieved using wget, then viewed offline. I've told CakePHP to handle .html extensions (using Router::parseExtensions('html');), then set up routes to the controller/action that look like a directory structure for static HTML files. I'm looking for a way to generate a URL that's relative to the page so that when I save the files (using wget) they'll still work when read from the hard drive.
As thaJeztah points out below, this isn't possible in CakePHP. Because CakePHP is abstractly mapping URLs to controllers & actions it does't really have any notion of 'serving a file' anymore (except in the /pages/subdirs, etc) so the only thing that makes sense for CakePHP is to provide a URL that starts at the root & works down to the .CSS files. (Much thanks to thaJeztah for pointing this out!)
Upvotes: 1
Views: 5053
Reputation: 3613
As a side-note, you can actually get a copy of a website using the "wget" command. (There's even a nice "Visual WGet" for Windows, which presents a friendly GUI for all the command line options). wget will download all the files and (if you use the -k / --convert-links option) will fix up all the links to be relative (to each document) so that they work offline.
It's important to wait till wget completely finishes, as wget does this weird two-phase thing where it FIRST gets all the files and THEN goes back and fixes up the links
Upvotes: 0
Reputation: 11148
From the API
If $path is prefixed with '/', the path will be relative to the webroot of your application. Otherwise, the path will be relative to your CSS path
So you could start the path with a /
and then point from there, that way you don't need to go backwards in directories.
Credit to this answer for pointing this out
Upvotes: 2