Good Day, I'm learning CodeIgniter with Smarty. My CSS file is stored in
/App01/application/views/css/main.css
To link my CSS I use:
<link rel="stylesheet" type="text/css" href="http://localhost:88/APP1/application/views/css/layout.css" media="screen" />
But CSS is not applied on my page. When I open CSS URL, I get a message:
Forbidden
You don't have permission to access /APP1/application/views/css/layout.css on this server.
Please, what am I doing wrong? I'd like to keep my CSS together with the view because in future I'd like to learn how to create multiple themes and I thing the CSS should be kept within the theme folder.
Can I replace URL path to CSS file with some Smarty variable so that when I move my application I do not need to change CSS URL path in templates manually?
Thank you in advance! Vojtech
Anything in the
/application
folder of CodeIgniter should be considered out-of-bounds. For the best security, you should actually consider keeping/application
above yourwww
orpublic_html
folder in a structure such as this:This makes your application code safer.
I’d advise creating your client-side scripts and CSS in a public folder. For example
public_html/css
andpublic_html/js
. Or, if you wanted to go down the theme route, possibly name each CSS file as the name of the theme, so you’d havecss/theme1.css
andcss/theme2.css
.If your site will always work from the root of a domain, then you can just use:
But if you feel that you’re going to be moving all sorts of things around, then consider preparing the file location in your controller before sending it to Smarty.
That will return:
Or whatever your CodeIgniter URL is.
This will help to link css to codeigniter.
The
link_tag
is used to link resources and you can usehelper
function. For example html helper, url helper, email helper, etc.In your controller you have to create a function something like
And your
index.php
inview
folder use link_tag keyword.Try adding a symlink to your servers document root folder. (www/public_html/htdocs)
This way you can access your css folder and keep the current structure.