[英]codeigniter extra url segments
I am making a site for a client and decided i would use code igniter.我正在为客户制作一个网站,并决定使用代码点火器。
The site essentially has two backends, one for designers, and one for a sales team.该网站基本上有两个后端,一个用于设计师,一个用于销售团队。 So after logging in, the user will be redirected to either所以登录后,用户将被重定向到
The sales team for example can view orders, containers, products, therefore i need a controller for each of these.例如,销售团队可以查看订单、容器、产品,因此我需要为每一个提供 controller。
The sales need to be able to view, edit, delete certain orders...销售人员需要能够查看、编辑、删除某些订单...
Basically my problem is i dont have enough url segments to play with.基本上我的问题是我没有足够的 url 段来玩。
My thoughts on solving my problem我对解决问题的想法
removing the orders, containers, products classes and making ALL of their methods as methods of the sales class, although this would mean a large number of methods and loading all models so it seemed kind of pointless.删除订单、容器、产品类并将其所有方法作为销售 class 的方法,尽管这意味着需要大量方法并加载所有模型,所以这似乎毫无意义。
removing the sales/designer classes and controlling what each kind of user has access to based on a user type stored in session data.删除销售/设计师类并根据存储在 session 数据中的用户类型控制每种用户可以访问的内容。
a way of having an extra url segment?有一个额外的 url 段的方法?
I appreciate any advice, I just dont want to get 3 weeks into the project and realise i started wrong from the beginning!我很感激任何建议,我只是不想在项目中投入 3 周,然后意识到我从一开始就错了!
Use folders.使用文件夹。
If you make a subfolder in /application/
called sales
you can put different controllers in there:如果您在/application/
中创建一个名为sales
的子文件夹,您可以在其中放置不同的控制器:
/application/
/sales/
orders.php /* Controller */
/design/
Then in orders.php
you will put your vieworders($id)
method and so on, and you will be able to acces it with domain.com/sales/orders/vieworders/id
.然后在orders.php
中输入vieworders($id)
方法等,然后就可以使用domain.com/sales/orders/vieworders/id
访问它。
You can also make subfolders in the /models/
and /views/
to organize your files.您还可以在/models/
和/views/
中创建子文件夹来组织文件。
Now, Access Control is something apart and it depends more in the auth system you are using.现在,访问控制是不同的,它更多地取决于您使用的身份验证系统。
Give the user/designer a privilege, a column in the user table for example, check the permission of the user at the beginning of the function, then prevent or execute it.给用户/设计者一个权限,比如用户表中的一列,检查function开头的用户的权限,然后阻止或执行。
This would be the exact way i would do it.这将是我这样做的确切方式。
Seems like you should have a look into the routing class.似乎您应该查看路由 class。 Might be a dirty solution but rerouting the sales/(:any) to something like sales_$1 would mean you'd make controllers with names like sales_orders.可能是一个肮脏的解决方案,但是将 sales/(:any) 重新路由到 sales_$1 之类的名称意味着您将使用 sales_orders 之类的名称制作控制器。 Same for the design part.设计部分也一样。
(FYI: $routing['sales/(:any)'] = 'sales_$1';
should do the trick; see application/config/routing.php). (仅供参考: $routing['sales/(:any)'] = 'sales_$1';
应该可以解决问题;请参阅 application/config/routing.php)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.