Codeigniter 中图片文件、css、js 等放在哪里? [英] Where do I put image files, css, js, etc. in Codeigniter?
问题描述
css文件夹和图片文件夹可以放在哪里?我在想视图文件夹里面?然而,控制器总是将路径重新路由到基本 url,因此我必须在 .html 文件中指定路径到它所在的位置,这是多余的.
Where is it acceptable to put css folders and image file folders? I was thinking inside the view folder? However the controller always reroutes the path to the base url so I have to specify the path in the .html file to where it sits, which is redundant.
推荐答案
我有这样的设置:
- 申请
- 系统
- 资产
- js
- 图像
- css
然后我有一个辅助函数,它根据我的设置简单地返回完整路径,类似于:
I then have a helper function that simply returns the full path to this depending on my setup, something similar to:
application/helpers/utility_helper.php:
function asset_url(){ return base_url().'assets/'; }
我通常会在同一个文件中保留与此类似的常见例程,并使用 codeigniter 的自动加载配置自动加载它.
I will usually keep common routines similar to this in the same file and autoload it with codeigniter's autoload configuration.
注意:用于
base_url()
访问的自动加载 URL 助手.Note: autoload URL helper for
base_url()
access.application/config/autoload.php:
$autoload['helper'] = array('url','utility');
然后,您将可以在整个代码中访问
asset_url()
.You will then have access to
asset_url()
throughout your code.这篇关于Codeigniter 中图片文件、css、js 等放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!