我们什么时候需要在codeIgniter中使用base_url()函数? [英] When do we need to use base_url() function in codeIgniter?
问题描述
我正在处理一个小项目,所有的URL都写有 base_url()
函数。所以我想的是这些 base_url()
函数如何帮助我的网址。我知道它将根据configs文件首选项前缀的url。但我只是想问:
I am working on a small project and all of my urls are written without base_url()
function. So I was thinking what does those base_url()
functions help with my urls. I know it will prefix the url based on configs file preferences. But simply I wanna ask
使用它们的优点是什么?
What is the advantage of using them ? and whats the disadvantage of not using them ?
推荐答案
主要的优点是:当您想要将项目迁移到在线或不同的服务器时;您不需要编辑您的硬编码链接。
The main advantage is that; when you want to migrate your project to online or in a different server; you won't need to edit your hard-coded links. The base_url() will make your inside links to get their base url dynamically.
echo base_url("blog/post/123");
将返回
http://example.com/blog/post/123
在 example.com
并会返回
http://jms.com/blog/post/123
这篇关于我们什么时候需要在codeIgniter中使用base_url()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!