Codeigniter 资产文件夹最佳实践 [英] Codeigniter assets folder best practice

查看:31
本文介绍了Codeigniter 资产文件夹最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 codeigniter 还很陌生,但我学得很好,我要添加一个 css、images、js、... 文件夹,但我不确定在哪里把它

I'm fairly new to codeigniter, But i'm learning well, I'm going to add a css, images, js, ... folder but I'm not sure where to put it

有人告诉我要创建一个公共"文件夹

Someone told me to make a 'public' folder

system
application
public
    css
    images

然后在你的 index.php(在公共文件夹中)进行相应的调整

And then in your index.php ( in the public folder ) adjust accordingly

$system_path = '../system';$application_path = '../application';

$system_path = '../system'; $application_path = '../application';

但是当我这样做时,我得到了一个 404(不是 ci 404,而是一个真正没有找到的)

But when I do that i get a 404 ( not the ci 404, but a really-not-found one )

有人知道我可能做错了什么吗?谢谢!

Anyone has any idea what I might be doing wrong? Thanks!

推荐答案

关于这个问题的另一个角度——我认为他们试图告诉你做的——是把你的申请 &系统文件夹从公共"html 文件夹上一层.这样您的源文件就无法访问.所以就像在 Mamp 中,公共文件夹称为 htdocs,在大多数网络托管中称为 html.

another angle on this -- and i think what they were trying to tell you to do - is putting your application & system folders one level up from the "public" html folder. that way your source files are not accessible. so like in Mamp the public folder is called htdocs, in most web hosting its called html.

 /application/html/
 /system     /html/

 // your main index page is in the public html folder
 /.…..       /html/index.php 

 // an assets folder in the public html folder with css, img, etc folders
 /.……        /html/assets/css/
 /.……        /html/assets/img/

然后在您的 index.php 中,路径会像向上"一级一样

then in your index.php, the path is going one level 'up' like

$system_path = '../system';
$application_folder = '../application';

奖励 - 这里有两个对我帮助很大的提示.1) 命名你的应用程序文件夹,然后你可以轻松地在不同版本之间切换,回滚"很快,等等.

BONUS - here are two tips that have helped me a lot. 1) Name your application folder, then you can easily switch between different versions, 'roll back' very quickly, etc.

 /app_alpha/html/
 /app_beta01/html/
 /app_beta02/html/

2) 将基本 url 放在 index.php 页面上——而不是在配置中.

2) Put the base url on the index.php page -- not in the config.

   $assign_to_config['base_url'] = 'https://awesomedomain.com'; 

这样你就可以有一个本地开发版本,单独的实时服务器版本——你永远不必担心写基本 URL,因为它在 index.php 页面上——而不是在配置中.

that way you can have a local development version, separate live server version -- and you never have to worry about over writing the base url because its on the index.php page - not in the config.

这篇关于Codeigniter 资产文件夹最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆