2012-01-30 147 views
0

我想将我的视图页面链接到另一个控制器。codeigniter路径问题

我test_view.php页

//this page address is base_url/controller1/function1 
<a href='controller1/function2'> test </a> 

如果我点击,页面地址为base_url/controller1/function1/controller1/function2这不是我的愿望。

我控制器

//the first function1 is to show my test_view page 
    function function1(){ 
     $this->load->view('test_view'); 
    } 

    //I can't get to this function2 with the link I used 
    function function2(){ 
     $this->load->view('funny'); 
    } 

任何人都可以帮我这个?非常感谢。

+0

感谢。 +1全部。 – FlyingCat 2012-01-30 16:32:08

回答

2

当然 - 你只需要告诉CodeIgniter的显示路径:

<a href="<?php echo site_url("controller1/function2");?>"> 

有一件事:这显示了您的网站的绝对路径在您的配置中定义,而不是相对路径。

我更喜欢相对路径,所以我喜欢创建一个名为site_path的通用函数来执行没有绝对URL的相同事情。我把它给我的普遍加载的图书馆之一,它看起来是这样的:

function site_path($url) { 
    return "/$url"; 
} 

这样做的好处是,如果我最初开发网站的子目录,我可以设置SITE_PATH到return "/subdirectory/$url",然后就我启动后删除子目录。

2

它链接到一个相对URL,你需要开始用“/”使用Web根

<a href='/controller1/function2'> test </a> 
2

您可以在test_view.php页面都使用下面的代码,
<a href='<?php echo base_url();?>controller1/function2'> test </a>