dgnin
dgnin

Reputation: 1597

Achieve static files in CakePHP regardless of the URL

I'm developing a site with CakePHP but I have a very basic doubt:

When I'm working on local, I use a virtual Host, then / means really the root of my project, then I can define all my links to static content like /static/content.css (i.e.). However, when I test the website I need to create a beta subdirectory, then the links should be changed to /beta/static/content.css.

Using relative paths like static/content.css isn't a solution because this will only work in the main page, whereas on other controllers and actions the files are unreachable because the system look for them in controller/action/static/content.css.

My first solution is creating a global constant that I must redefine in every place I test my page (my local server, my remote server, the client remote server...) but I hope that CakePHP provides a way to solve this problem in a more elegant way.

Thank you for your attention and help.

Upvotes: 0

Views: 152

Answers (2)

floriank
floriank

Reputation: 25698

Sounds pretty weird to me. Why not have a branch in your git/svn/whatever repo called "beta" and simply use: example.com (live site) and beta.example.com (beta site) for testing with separated folders, vhosts and databases. You said testing, so I would not try to use beta features on a live db.

Upvotes: 0

dogmatic69
dogmatic69

Reputation: 7585

This is why you should not be using static urls for anything, but instead be doing things like echo $this->Html->css('your_file'); which would point to /webroot/css/your_file.css

Upvotes: 2

Related Questions