Codeigniter中资产的最佳做法 [英] Best practice for assets in codeigniter
问题描述
我是Codeigniter的新手,我想知道存储js/css/images/等的最佳位置在哪里?通常,我习惯于:
I'm new to codeigniter and was wondering where the best place is to store js/ css/ images/ etc? Typically I'm used to:
/
--/application
--/system
--/public
----/css
----/js
----/images
但是使用这种目录结构的最佳方法是什么?我在研究中发现的所有内容是,通常的代码点火器项目的资产都位于应用程序和系统文件夹的旁边.
But what would be the best way to use such a directory structure? All that I've found in my research is that commonly codeigniter projects have their assets sitting next to the application and system folders.
推荐答案
好吧,将数据放在目录结构的根目录级别是否危险?保护密钥文件夹(例如系统)免受外界攻击的所有方法是.htaccess
Well, isn't it dangerous to have the data on the root level of the directory structure? All that is protecting the key folders (e.g. system) from outsiders is a .htaccess
假设您正在运行Apache,则 .htaccess
并带有全部拒绝
即可.
Assuming you're running Apache, .htaccess
with deny from all
should be fine.
如果没有,这就是为什么通常在每个文件的开头看到这样的原因之一:
If not, this is one reason why you usually see something like this at the beginning of each file:
defined('BASEPATH') or exit('No direct script access.');
这可以确保无法直接访问脚本.
This ensures the script can't be accessed directly.
您还可以将应用程序和系统文件保留在Web根目录下,如下所示:
You may also be able to keep your application and system files below the web root, something like this:
htdocs
application
system
public_html
index.php
public
css
js
img...
只需在index.php中使用相对路径来定义您的CI路径:
Just use a relative path in index.php to define your CI paths:
$system_path = '../system';
$application_folder = '../application';
这篇关于Codeigniter中资产的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!