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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀