【发布时间】:2018-06-30 03:52:53
【问题描述】:
我目前正在开发我的个人博客,但我的路线有问题。假设我有一个名为
的控制器博客
<?php
class Blog extends CI_Controller {
public function index(){
$data['posts'] = $this->BlogModel->get_post();
$this->load->view('frontend/header');
$this->load->view('frontend/navbar');
$this->load->view('frontend/BlogContent',$data);
$this->load->view('frontend/footer');
}
public function view($slug = NULL){
$data['post'] = $this->BlogModel->get_post($slug);
if(empty($data['post'])){
show_404();
}
$data['title'] = $data['post']['title'];
$this->load->view('frontend/header');
$this->load->view('frontend/navbar');
$this->load->view('frontend/blog/view',$data);
$this->load->view('frontend/footer');
}
}
?>
我的路线是这样的:
$route['blog/(:any)'] = 'blog/view/$1';
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
然后我尝试访问这部分 http://localhost/cathode/blog/post-one 工作正常
但在访问这些部分后尝试访问导航栏菜单时,我的 base_url 包含在“博客”控制器中。
所以当我尝试访问“home”菜单时,路由将指向http://localhost/cathode/blog/home,而实际上我的base_url 是http://localhost/cathode/,我该如何解决这个问题?
谢谢
【问题讨论】:
-
请分享您的
$config['base_url']、$config['uri_protocol']、$config['index_page']价值观 -
$config['base_url'] = 'localhost/cathode'; $config['uri_protocol'] = 'REQUEST_URI'; $config['index_page'] = '';这个对吗? @DaniyalNasir
-
我可以看到带有附加 base_url 的导航栏的 html。
-
@DaniyalNasir
-
您的 Blog 是您的控制器名称,因此应该是
<a class="nav-link" href="<?php base_url('Blog/home');?>home">HOME <span class="sr-only">(current)</span></a>
标签: php codeigniter