dpzp5127 2010-01-18 14:57
浏览 64
已采纳

CodeIgniter自定义管理URI路由

UPDATE: SOLVED! For the broken pages I simply made an admin controller. That has a function for each model now :) Happy days!

Trying to house my admin function in the same controller as my front-end code. To do this I am setting up some custom routes so that admin can be accessed via:

/admin/controller/id // instead of /controller/admin/id
/admin/controller/create // instead of /controller/create
/admin/controller/detail/id // instead of /controller/detail/id
/admin/controller/update/id // instead of /controller/update/id
/admin/controller/delete/id // instead of /controller/delete/id

My current routes work perfectly for detail, create, update, delete

$route['admin/(:any)/detail'] = "$1/detail"; // WORKS!!!
$route['admin/(:any)/detail/(:num)'] = "$1/detail/$2"; // WORKS!!!
$route['admin/(:any)/create'] = "$1/create"; // WORKS!!!
$route['admin/(:any)/create/(:num)'] = "$1/create/$2"; // WORKS!!!
$route['admin/(:any)/update'] = "$1/update"; // WORKS!!!
$route['admin/(:any)/update/(:num)'] = "$1/update/$2"; // WORKS!!!
$route['admin/(:any)/delete'] = "$1/delete"; // WORKS!!!
$route['admin/(:any)/delete/(:num)'] = "$1/delete/$2"; // WORKS!!!

HOWEVER I cannot get the admin page to work with an ID. I can reroute the index page, but will be unable to use pagination if I cannot pass the ID.

$route['admin/(:any)'] = "$1/admin"; // WORKS!!!
$route['admin/(:any)/(:num)'] = "$1/admin/$2"; // EPIC FAIL :( 404's

Can someone please help me solve this problem, or even suggest an alternative solution of application structure.

  • 写回答

3条回答 默认 最新

  • dty97501 2010-01-19 08:32
    关注

    Make sure your regex routes (that includes routes with :num and :any) must go AFTER the default_controller route.

    For more ways to create a decent admin panel, take a look at my article on creating an admin panel in CodeIgniter. There are three decent ways to do it, this article explains the pro's and con's of each.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数
  • ¥15 关于#线性回归#的问题:【统计】回归系数要转化为相关系数才能进行Fisher' Z转化吗(相关搜索:回归模型)