子文件夹中的路由控制器 - 代码指示器 [英] routing controllers in sub folders - codeigniter

查看:110
本文介绍了子文件夹中的路由控制器 - 代码指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我想分离系统的前端和后端。我已经在控制器内创建了2个文件夹作为前端和后端

since i want to separate the frontend and backend of the system. i have created 2 folders inside controllers as frontend and backend

下面是我的控制器文件夹的结构

Below is the structure of my controller folder

controller
 --frontend
   ---store.php
   ---processing.php
   ---profile.php
   ---authenticate.php
   ---register.php 

 --backend
   ---authenticate.php
   ---stats.php
   ---users.php
   ---property_manage.php
   ---register.php 

我可以使用

frontend/store/add
frontend/store/manage
......

backend/stats/sales
backend/stats/payments
.....

但我想从网址中取出前端和后端段。

but i want to take off the frontend and the backend segments from the url.

我检查了codeigniter的路由功能,但根据我的知识,我需要单独指定每个路由。由于我有大约12个控制器,每个都有大约10-15个功能,我可能需要指定每个功能的路线。

I checked the routing feature in codeigniter but according to my knowledge i need to individually specify each route. Since i have about 12 controllers and each has around 10 -15 functions i might have to specify each and every function to the route.

是有任何其他有效的方式来实现使用路由或任何其他方式? (不使用任何htaccess)

is there any other efficient way to achieve using routing or any other way? (without using any htaccess)

推荐答案

执行此操作:

  $route['store/(:any)'] = 'frontend/store/$1';
  $route['processing/(:any)'] = 'frontend/processing/$1';
  $route['profile/(:any)'] = 'frontend/profile/$1';

与后端相同:

 $route['backend/(:any)'] = 'backend/authenticate/$1';

您不必在routes.php中为控制器的每个函数创建每个规则,

You don't have to create each rule in routes.php for every function of controller, instead one rule per controller will be enough as mentioned above.

URI路由:CodeIgniter用户指南

$ 1 表示第一个表达式,(:any)是表达式,每个规则可以有多个表达式,表达式表示为 $ 1 $ 2 等等。

$1 represent the first expression, here (:any) is the expression, you can have multiple expression on each rule, and expression is represented as $1, $2 and so on on the other side.

类似地,(:num)将匹配只包含数字 (\d +)将匹配任何数字([az] +)将匹配任何字母文本。

Similarly, (:num) will match a segment containing only numbers, (:any) will match a segment containing any character, (\d+) will match any digit, ([a-z]+) will match any alpha text.

这篇关于子文件夹中的路由控制器 - 代码指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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