CodeIgniter Anchor错误:在此服务器上找不到URL [英] CodeIgniter Anchor error: URL not found on this server

查看:212
本文介绍了CodeIgniter Anchor错误:在此服务器上找不到URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了好几个小时才能建立一个简单的锚点链接,但没有成功。



我的控制器是

  class Welcome extends CI_Controller {
public function index()
{
$ this-> load-> view ('模板');
}

public function contact()
{
$ this-> load-> view('contact');
}
}

My template.php view基本上是一个有

 < a class =menuhref> <?php echo anchor('welcome / contact /','Contato')?> < / a> 

我在views目录中有一个contact.php。



我的 config.php

  $ config ['base_url'] ='localhost'; 

$ config ['index_page'] ='index.php';

加载 template.php 点击链接contato我想驱动系统到函数 contact(),负责打开页面 contact.php 。但是,我有以下错误:


/ localhost / index.php / welcome / contact / p>

缺少什么?

解决方案

base_url config MUST 包含协议尾部斜杠。 / p>

config.php 档案:


您的CodeIgniter根的URL。通常,这将是您的基本URL,

带有斜杠:

  http://示例。 com / 

如果没有设置,CodeIgniter会猜测协议,域
$ b $


因此,您可以设置 base_url 如下,或在这种情况下,只需将其留空:

  $ config ['base_url'] ='http:// localhost /'; 

#base_url应该是绝对的,如果你在子文件夹中安装了CI:
$ config ['base_url'] ='http:// localhost / path / to / codeigniter_folder / ';

边注:,以便使用URL辅助函数code> anchor(),首先加载助手文件 $ this-> ); (或通过 autoload.php 配置文件自动加载助手)






为什么 base_url 配置会影响 anchor $ c> function?



anchor() 函数,使用 site_url() 帮助函数来确定URL地址的超链接。



site_url() 本身,使用两个 base_url index_page

因此,如果您为 base_url 和/或 index_page configs, anchor()函数将无法正常工作。


I have been for hours to make a simple anchor link working without success.

My controller is

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->view('template');
    }

    public function contact()
    {
        $this->load->view('contact');
    }        
}

My template.php view is basically a file with

<a class="menuhref"> <?php echo anchor('welcome/contact/','Contato')?> </a>

I also have a contact.php in the views directory.

My config.php is

$config['base_url']   = 'localhost'; 

$config['index_page'] = 'index.php';

When the template.php loads and I click in the link "contato" I would like to drive the system to the function contact() that would be responsible to open the page contact.php. However, I have got the following error:

"/localhost/index.php/welcome/contact" was not found on this server

What is missing?

解决方案

The base_url config MUST contains the protocol and a trailing slash as well.

From the config.php file:

URL to your CodeIgniter root. Typically this will be your base URL,
WITH a trailing slash:

http://example.com/

If this is not set then CodeIgniter will guess the protocol, domain
and path to your installation.

Hence, you could set the base_url as follows, or in this case simply leave it blank:

$config['base_url'] = 'http://localhost/';

# base_url should be absolute, If you've installed CI in sub-folder:
$config['base_url'] = 'http://localhost/path/to/codeigniter_folder/';

Side-note: in order to use URL helper functions such as anchor(), load the helper file at first: $this->load->helper('url'); (or load the helper automatically via autoload.php config file).


Why does base_url config affect anchor() function?

anchor() function, uses site_url() helper function to determine the URL address of the hyperlink.

And the site_url() itself, uses two base_url and index_page configs to create the URL address.

Hence if you assign a wrong value to base_url and/or index_page configs, the anchor() function won't work properly.

这篇关于CodeIgniter Anchor错误:在此服务器上找不到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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