CodeIgniter + CSS

Good afternoon, I am 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 the 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 would like to save my CSS along with the presentation, because in the future I would like to learn how to create several themes, and I believe that CSS should be stored in the theme folder.

Is it possible to replace the URL in the CSS file with some Smarty variable so that when moving my application I don’t have to manually change the URL of the URL in the templates?

Thank you in advance! Voitech

+6
source share
3 answers

Everything that is in the /application CodeIgniter folder should be considered as beyond. For maximum security, you should consider storing /application over your www or public_html folder in a structure like this:

 – application – controllers – models – views – ... – system – core – libraries – ... – public_html – index.php 

This makes your application code more secure.

Id advises creating your client scripts and CSS in a shared folder. For example public_html/css and public_html/js . Or, if you want to go down a topic of a route, perhaps name each CSS file as the name of the theme, so youd have css/theme1.css and css/theme2.css .

If your site will always work from the root of the domain, you can simply use:

 <link rel="stylesheet" type="text/css" href="/css/layout.css" media="screen" /> 

But if you feel that you will be collecting all kinds of things, think about preparing the location of the file in the controller before sending it to Smarty.

 $this->load->helper('url'); $this->smarty->assign('css_file', base_url("css/theme1.css")); 

This will return:

 http://localhost/app1/css/theme.css 

Or whatever your CodeIgniter url is.

+12
source

This will help link css to codeigniter.

link_tag used to link resources, and you can use the helper function. For example html helper, url helper, email helper, etc.

In your controller you need to create a function similar to

 <?php class Home extends CI_Controller{ public function helper(){ $this->load->helper('html'); $this->load->view('index'); } } ?> 

And your index.php folder in view uses the link_tag keyword.

 <html> <head> <title></title> <?php echo link_tag('App01/application/views/css/main.css');?> </head> <body> <?php ....... ?> </body> </html> 
+1
source

Try adding a symlink to the root folder of your server documents. (Www / public_html / HTDOCS)

 cd (document root folder) ln -s (/App01/application/views/css) . 

This way you can access your css folder and save the current structure.

0
source

Source: https://habr.com/ru/post/905895/


All Articles