Codeigniter路由控制器子文件夹

编程入门 行业动态 更新时间:2024-10-26 16:24:33
本文介绍了Codeigniter路由控制器子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有路由和控制器的问题。我有两种类型的控制器:第一种类型用于管理网页,第二种类型用于cms,我更喜欢把它们放在一个子文件夹。示例:

/controller/site.php(对于网页) / controller / admin / cms)

在routes.php中我写了:

$ route ['(:any)'] =site / $ 1; $ route ['admin /(:any)'] =admin / $ 1;

我有这样设置的.htacces文件:

RewriteEngine on RewriteCond $ 1!^(index\.php | images | robots\.txt | css | js | font | woff | ttf | svg | eot | favicon\.ico) RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule ^(。*)$ index.php? / $ 1 [L]

和config.php上的此变量:

$ config ['index'] ='';

,但它仅适用于site。如果我写mywebsite / admin / login例如,它返回404错误。

我也发现MY_Router扩展CI_Route但不工作。 p>

有人可以帮我解决这个问题吗?

解决方案

code> 路由

$ route ['admin /(:any)'] =admin / $ 1; $ route ['(:any)'] =site / $ 1;

否则将始终命中任何到 site 。您必须给它一个匹配任何之前匹配 admin 的机会。

I've a problem with routes and controller. I've got 2 types of controller: first type is used to manage the webpages, second type is used for cms and I prefer to put them in a sub-folder. Example:

/controller/site.php (for webpages) /controller/admin/ (for controllers to manage cms)

in routes.php I've write:

$route['(:any)'] = "site/$1"; $route['admin/(:any)'] = "admin/$1";

I've got the file .htacces set in this way:

RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt|css|js|font|woff|ttf|svg|eot|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]

and this variable on config.php:

$config['index'] = '';

but it works only for "site". If I write "mywebsite/admin/login" for example, it return 404 error.

I've found also MY_Router to extend CI_Route but doesn't work.

Can someone help me to resolve this problem ?

解决方案

Put the admin route before the any route:

$route['admin/(:any)'] = "admin/$1"; $route['(:any)'] = "site/$1";

otherwise it will always hit any and redirect to site. You have to give it a chance to match admin before matching any.

更多推荐

Codeigniter路由控制器子文件夹

本文发布于:2023-11-01 11:23:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   控制器   文件夹   Codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!