(Codeigniter) 我可以使用带参数的默认控制器吗?
(Codeigniter) Can I use default controller with parameter?
你好朋友,我正在使用 codeigniter,但我需要你的帮助。
我正在使用默认控制器,例如:
$route['default_controller'] = 'generals/view/index';
但是当我进入本地主机时,我看到了 404 错误。
我在下面展示我的控制器。
public function view($page){
$this->load->view('templates/header');
$this->load->view('sections/'.$page);
$this->load->view('templates/footer');
}
非常感谢你的帮助
根据Codeigniter Documentation,default_controller是保留路由:
This route points to the action that should be executed if the URI contains no data,
which will be the case when people load your root URL. The setting accepts a
controller/method value and index() would be the default method if you don’t specify
one. In the above example, it is Welcome::index() that would be called.
请将您的 default_controller 更新为:
$route['default_controller'] = 'generals/view';
并在您的控制器中
public function view($page = 'index'){
$this->load->view('templates/header');
$this->load->view('sections/'.$page);
$this->load->view('templates/footer');
}
对于 uri 的其余部分,您需要定义另一条路线。
你好朋友,我正在使用 codeigniter,但我需要你的帮助。
我正在使用默认控制器,例如:
$route['default_controller'] = 'generals/view/index';
但是当我进入本地主机时,我看到了 404 错误。
我在下面展示我的控制器。
public function view($page){
$this->load->view('templates/header');
$this->load->view('sections/'.$page);
$this->load->view('templates/footer');
}
非常感谢你的帮助
根据Codeigniter Documentation,default_controller是保留路由:
This route points to the action that should be executed if the URI contains no data,
which will be the case when people load your root URL. The setting accepts a
controller/method value and index() would be the default method if you don’t specify
one. In the above example, it is Welcome::index() that would be called.
请将您的 default_controller 更新为:
$route['default_controller'] = 'generals/view';
并在您的控制器中
public function view($page = 'index'){
$this->load->view('templates/header');
$this->load->view('sections/'.$page);
$this->load->view('templates/footer');
}
对于 uri 的其余部分,您需要定义另一条路线。