Reputation: 11
So, I've searched and found some simillar questions, but none of the answers worked for me.
Let me explain the situation. I've built a CakePHP 3 and it works great in my local machine. When I finally deployed to the server, things got really weird.
Basically, when I use the link() or css() or other methods of the Html Helper, CakePHP adds the whole path (starting from the root). So, I'd write something like:
<?= $this->Html->css( 'main.css' ) ?>
and the output should be:
<link rel="stylesheet" href="/css/main.css"/>
but what I'm getting is this:
<link rel="stylesheet" href="/var/www/html/mydomainname.net/web/css/main.css"/>
I did some research on the hosting company FAQs and documentation, and I found out that the Apache DocumentRoot is set to the '/', which is of course not desired, since CakePHP requires it to be set to the app's web root folder. The thing is, since this is a shared hosting environnment, I cannot change it!
Any ideas?
Upvotes: 1
Views: 181
Reputation: 11
Well, the solution I've found was simply to not use Html Helper methods such as link() and css(), and use plain good old html instead. The ideal would probably edit Apache settings and make DocumentRoot point to the webroot folder in my app, but my hosting company support was not as helpful as I'd wished them to be.
Upvotes: 0
Reputation: 187
According to the docs:
This method of CSS inclusion assumes that the CSS file specified resides inside the /app/webroot/css directory if path doesn’t start with a ‘/’.
As a workaround then, you might be able to try:
<?php $this->Html->css('/css/main.css') ?>
to prevent cake from making assumptions.
From here: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::css
Upvotes: 0