在全新安装的 codeigniter 2.1.3 中,我有一个具有两个功能的控制器“home.php”:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->load->view('home');
}
public function homefunction()
{
$this->load->view('homefunction');
}
}
我有一个视图'home.php'。锚点代表菜单:
<p>Home</p>
<br/>
<a href="home">Home</a>
<a href="home/homefunction">Home Function</a>
和一个视图'homefunction.php'
<p>Function in the Home controller</p>
<br/>
<a href="home">Home</a>
<a href="home/homefunction">Home Function</a>
我的路线:
$route['default_controller'] = "home";
我已经用 .htaccess 和 config.php 从 URL 中“消除”了 index.php,我的 .htaccess 是:
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [PT,L]
在我设置的 config.php 文件中:
$config['base_url'] = 'http://localhost/test';
$config['index_page'] = '';
现在我运行http://localhost/test
并且我的主页加载了菜单。浏览器中的网址是localhost/test/
. 然后我单击浏览器中的 url 变为的“主页”锚菜单项localhost/test/home
。我单击主页功能页面加载的另一个菜单项“主页功能”,网址变为localhost/test/home/homefunction
. 在主页功能视图的菜单中,单击“主页”项,网址变为localhost/test/home/home
. 我期待成为 localhost/test/home
. 然后我单击菜单项“主页功能”,主页功能视图未加载并且 url 变为localhost/test/home/home/homefunction
,主页功能页面未加载我再次单击主页并进入 url localhost/test/home/home/home
,每次单击主页功能菜单项时都会继续然后主页菜单项在 url 中添加主页部分。
我知道这很简单,可能与路由有关,但我卡住了,我在谷歌上找不到类似的问题。任何人都可以帮忙吗?