Codeigniter和“新闻部分"教程问题 [英] Codeigniter "News section" tutorial issue

查看:44
本文介绍了Codeigniter和“新闻部分"教程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对URI有问题.我试图浏览帖子,但看不到答案.

I have a problem with the URI. I've tried to look through the post, but couldn't see the answer.

教程可以在这里找到: http://codeigniter.com/user_guide/tutorial/news_section.html

Tutorial can be found here: http://codeigniter.com/user_guide/tutorial/news_section.html

基本上,我复制了所有内容,并且效果很好,但是有人认为我不这样做知道是我的浏览器还是配置不正确的东西.

Basically I replicated all and it works fine, but there one think where I don't know whether is my browser or I miss-configured something.

在"views/news/index.php"中,按照教程,我有以下代码:

In the "views/news/index.php" I have the following code as per tutorial:

<h2><? echo $news_item['title'] ?></h2>
<div id="main">
    <? echo $news_item['text']?>
</div>
<p>[b]<a href="news/<? echo $news_item['slug']?>">View Article</a>[/b]</p>

现在的问题是,当我在浏览器中查看源html时,我看到的链接为:

Now the problem is that when I look into the source html on my browser I see the link as:

查看文章

我认为这是正确的.但是当我单击时,它指向我:

Which I assume is correct. But when I click on, it points me to:

localhost/CI/index.php/news/news/firstnews

localhost/CI/index.php/news/news/firstnews

正如您所看到的,新闻"在URI中重复了两次.看起来浏览器只是将href值附加到打开的URI,而不是将其清理到index.php并将其添加到那里.

As you can see the "news" is repeated twice in the URI. It looks like the browser is simply appending the href value to the URI that is open, instead of cleaning it down to index.php and add it there.

我试图从href值中删除新闻"位,并且效果很好.

I tried to remove the "news" bit from the href value and it works fine.

如果有什么用,我正在使用Chome.

I am using Chome if that makes any difference.

那是我的错吗?还是这只是本教程中的错误?

Is that my misstake? Or this is just an error in the tutorial?

推荐答案

为避免此类错误,我在写下链接时经常使用 base_url().像这样:

In order to avoid this kind of mistakes I often use base_url() when writing down the links. Like this:

<?php echo anchor(base_url('news/'.$news_item['slug']),View article); ?>

请注意,我使用的是 anchor()& URL帮助器 base_url()函数.有关更多信息,请访问:

Note that I use the the anchor() & base_url() functions of the URL helper. More info at:

http://codeigniter.com/user_guide/helpers/url_helper.html

这篇关于Codeigniter和“新闻部分"教程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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