>我正在研究代码点火器 4,当我点击菜单 URL 更改时遇到问题
我的控制器是
<?php namespace AppControllers;
class Pages extends BaseController
{
public function index($page='Home')
{
if(!is_file(APPPATH.'/views/pages/'.$page.'.php')){
die;
throw new CodeIgniterExceptionsPageNotFoundException($page);
}
return view("pages/{$page}");
}
public function about($page='About')
{
if(!is_file(APPPATH.'/views/pages/'.$page.'.php')){
die;
throw new CodeIgniterExceptionsPageNotFoundException($page);
}
return view("pages/{$page}");
}
public function contact($page='Contact')
{
if(!is_file(APPPATH.'/views/pages/'.$page.'.php')){
die;
throw new CodeIgniterExceptionsPageNotFoundException($page);
}
return view("pages/{$page}");
}
}
"我的路线"页面
$routes->get(':/', 'Pages::index');
$routes->get(':/', 'Pages::about');
$routes->get(':/', 'Pages::contact');
而 html 是
<ul class="nav navbar-nav">
<li class="active"><a href="pages/">Home</a></li>
<li><a href="pages/about">About</a></li>
<li><a href="pages/contact">Contact</a></li>
</ul>
初始它会正常工作,但是当我再次单击菜单中时,它的 url http://localhost/pages/contact 更改为喜欢这个 URL http://localhost/pages/pages/contact 我不知道我错在哪里,请建议我
更改为绝对路径
<ul class="nav navbar-nav">
<li class="active"><a href="/pages/">Home</a></li>
<li><a href="/pages/about">About</a></li>
<li><a href="/pages/contact">Contact</a></li>
</ul>