Codeigniter:Base_url 似乎不起作用
我开发了一个简单的网站,可以从 Twitter 公共时间线获取推文,将其缓存 60 秒等等。我最近将主机从 Hostgator 移至 Mediatemple,我的网站之前在 Hostgator 上运行良好。
我的应用程序不使用数据库连接,也不使用任何形式的平面文件数据库。推文缓存在根目录中存储的 XML 文件中,但其中大部分内容并不重要。
url 助手已被包含在内,如下所示(这是我的 autoload.php 中的助手行): $autoload['helper'] = array('url');
我还删除了我的使用 .htaccess 指令从 URL 获取 index.php 文件,这又是以前在 Hostgator 上运行的(请参阅下面的 .htaccess 代码):
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
在我的 home.php 视图文件(位于应用程序内部的views文件夹中)中,我使用函数 base_url() 之前在我的视图文件内的 Hostgator 上工作,并将其附加到我的标头中的基本 href 值:
下面是我的 base_url 值在 config.php 文件中的样子:
$config['base_url'] = "http://threetune.com/";
尽管似乎发生的情况是根本看不到 base_url。它似乎没有回显 base_url 的值,因为由于某种原因它似乎为空。
让事情变得更奇怪的是,我在另一个名为“fetch.php”的视图文件中有一个链接,并且由于某种原因,它似乎正在删除该值(XSS 过滤已关闭): Threetune/show 部分是看不到的,我只看到一个像这样的空 href 值
任何人都可以看到我可能做的任何错误吗?某种 Mediatemple 服务器限制或需要设置的 PHP.ini 标志?谢谢你,我希望我的描述足够。
I have developed a simple site that fetches tweets from the Twitter public timeline, caches them for 60 seconds and so on. I have recently moved hosts from Hostgator to Mediatemple and my site was previously working fine on Hostgator.
My application doesn't use a database connection, nor does it use any form of flat-file database either. Tweets are cached in an XML file stored in the root directory, not that most of that is important.
The url helper is being included as can be seen below (this is my helpers line from autoload.php): $autoload['helper'] = array('url');
I have also removed my index.php file from the URL using .htaccess directives and once again this was previously working on Hostgator (see my .htaccess code below):
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
In my home.php view file which is in the views folder inside of application, I am using the function base_url() which was previously working on Hostgator inside of my view files and appending it a base href value in my header: <base href="<?php echo base_url(); ?>" />
Here is what my base_url value looks like in the config.php file:
$config['base_url'] = "http://threetune.com/";
Although what appears to be happening is that the base_url is not to be seen at all. It doesn't appear to be echoing out the value of base_url as it appears to be empty for some reason.
What makes things weirder is that I have a link in another view file called 'fetch.php' and for some reason it appears to be stripping out the value (XSS filtering is off): <a href="threetune/show"><img src="assets/images/cookie.jpg" /></a>
The threetune/show part is not to be seen and I only see an empty href value like this <a href=""><img src="assets/images/cookie.jpg" /></a>
Can anyone possibly see anything wrong that I may have done, some kind of Mediatemple server limitation or PHP.ini flag that needs to be set? Thank you and I hope I was descriptive enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也在网格上。重新阅读您的问题并进行一些测试(这对我有用)后,我认为发生的情况是您忘记加载
url
帮助程序。如果您希望通过
base_url()
在应用程序中使用站点基本 url,则需要首先加载url
帮助程序。通过 config/autoload.php 或在控制器中手动加载它。否则你可以使用 config/constants.php 来定义常量变量:
I am on the grid as well. After re-reading your question and doing a little testing (it works for me), I think what's happening is you forgot to load the
url
helper.If you want the sites base url available to you to use in the application via
base_url()
, you need to load theurl
helper first. Either via config/autoload.php or load it manually in your controller.Otherwise you could use config/constants.php to define constant variables:
关于 base_url 的快速说明 - 动态设置此变量可能是个好主意,因为它将允许您的网站支持多个域。
http://thecodeabode.blogspot.com/2010/10/codeigniter -supporting-multiple-domains.html 通过提供考虑协议和端口的脚本对此进行了一些扩展。
Just a quick note on base_url - might be a good idea to dynamically set this variable, as it will allow your site to support multiple domains.
http://thecodeabode.blogspot.com/2010/10/codeigniter-supporting-multiple-domains.html expands a bit on this by giving scripts that take into consideration protocol and port.