我在我的 route.php 中输入了 - $route['admin/students'] = 'view_student'
.这里 view_student 是 Controller 名称。现在,当我从“localhost/school/admin”页面调用 <a href="admin/students">Students</a>
时,比一切正常;但是当我改变我的路线时 - $route['/school/admin/students'] = 'view_student'
,并从“localhost/school/admin”页面将其称为 <a href="/school/admin/students">Students</a>
, 而不是显示 404 页面。这里有什么问题吗?
最佳答案
试试这个代码,它可能对你有帮助:
这里的dashboard是controller的名字
//this will route as localhost/appFolder/admin/index
$route['admin'] = 'dashboard'; // for your index page
//this will route as localhost/appFolder/admin/method_name
$route['admin/(:any)'] = 'dashboard/$1';
//this will route as localhost/appFolder/admin/method_name/param1
$route['admin/(:any)/(:any)'] = 'dashboard/$1/$2';
按赞链接路线
// for your index page
<a href="<?php echo base_url('admin/index'); ?>"></a>
// for your other pages
<a href="<?php echo base_url('admin/method_name'); ?>"></a>
链接其他定义的 Controller
<a href="<?php echo base_url('otherControllerName/method_name'); ?>"></a>
关于php - PHP Codeigniter 中的 URL 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38292243/