PHP Codeigniter中的URL路由 [英] URL routing in PHP Codeigniter

查看:48
本文介绍了PHP Codeigniter中的URL路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在route.php中输入- $ route ['admin / students'] =‘view_student'。这里的view_student是控制器名称。现在,当从 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页。

I am having entry in my route.php like - $route['admin/students'] = 'view_student'. Here view_student is controller name. Now when from "localhost/school/admin" page I call <a href="admin/students">Students</a>, than everything works fine; But when I change my route like - $route['/school/admin/students'] = 'view_student', and call it from "localhost/school/admin" page as <a href="/school/admin/students">Students</a>, than 404 page is shown. Whats wrong in here?

推荐答案

尝试使用此代码可能会对您有所帮助:

此处仪表板是控制器的名称

Here dashboard is the name of 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>

要链接定义的其他控制器,就像

 <a href="<?php echo base_url('otherControllerName/method_name'); ?>"></a>

这篇关于PHP Codeigniter中的URL路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆