我在wampserver上使用codeigniter,对模型控制器视图非常陌生,而且我试图很好地理解它的工作原理。目前,我正在尝试做一个控制器的基本创建:在/application/controllers/pages.php中,我只是这样做的:<?php class Pages extends CI_Controller{ public function one(){ echo 'hello world'; } }?>所以,是的,这是非常基本的,但是当我尝试使用chrome达到该方法时,我陷入了404错误:http:// localhost / test / pages / one /我在互联网上看过几本与我做的事情相同的教程,但是他们在他们的网页中看到了“ hello world”。我发现这可能是因为我没有在URL中键入index.php,但是我修改了config.php和route.php使其不再需要键入它:config.php:$config['base_url'] = 'http://localhost/test';/*|--------------------------------------------------------------------------| Index File|--------------------------------------------------------------------------|| Typically this will be your index.php file, unless you've renamed it to| something else. If you are using mod_rewrite to remove the page set this| variable so that it is blank.|*/$config['index_page'] = '';route.php:$route['default_controller'] = 'pages/view';$route['pages'] = 'pages/$1';$route['(:any)'] = 'pages/view/$1';$route['404_override'] = '';$route['translate_uri_dashes'] = FALSE;最让我困扰的是,当我使用此codeigniter的示例时,它运行良好,并且没有出现404错误:class Pages extends CI_Controller{public function view($page = 'home'){ if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = ucfirst($page); // Capitalize the first letter $this->load->view('templates/header', $data); $this->load->view('pages/'.$page, $data); $this->load->view('templates/footer', $data);}}如果我尝试创建另一个功能,它将被完全忽略。我想我的路由文件有问题或codeigniter的安装有问题,但在这种情况下,我希望在重新安装所有设备之前先询问一下...有人对我的问题有答案吗?非常感谢。
1 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
更改您的路线
$route['default_controller'] = 'pages/view';
$route['pages'] = 'pages/$1';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
至
$route['default_controller'] = 'pages/one';
$route['pages'] = 'pages/$1';
$route['(:any)'] = 'pages/one/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
- 1 回答
- 0 关注
- 146 浏览
添加回答
举报
0/150
提交
取消