codeigniter 额外的 url 段
我正在为客户制作一个网站,并决定使用代码点火器。
该网站本质上有两个后端,一个用于设计师,另一个用于销售团队。因此,登录后,用户将被重定向到
- mysite.com/sales/
- mysite.com/design/
例如,销售团队可以查看订单、容器、产品,因此我需要为每一个提供一个控制器。
- mysite.com/sales/orders/
销售人员需要能够查看、编辑、删除某些订单...
- mysite.com/sales/orders/vieworder/235433
基本上我的问题是我没有足够的网址段可以使用。
我对解决问题的想法
删除订单、容器、产品类并将它们的所有方法作为销售类的方法,尽管这意味着大量的方法并加载所有模型,所以它似乎毫无意义。
删除销售/设计师类并根据会话数据中存储的用户类型控制每种用户有权访问的内容。
一种拥有额外 url 段的方法?
我很感激任何建议,我只是不想在项目进行了三周后才意识到我从一开始就错了!
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
- mysite.com/sales/
- mysite.com/design/
The sales team for example can view orders, containers, products, therefore i need a controller for each of these.
- mysite.com/sales/orders/
The sales need to be able to view, edit, delete certain orders...
- mysite.com/sales/orders/vieworder/235433
Basically my problem is i dont have enough url segments to play with.
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.
removing the sales/designer classes and controlling what each kind of user has access to based on a user type stored in session data.
a way of having an extra url segment?
I appreciate any advice, I just dont want to get 3 weeks into the project and realise i started wrong from the beginning!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用文件夹。
如果您在
/application/
中创建一个名为sales
的子文件夹,您可以在其中放置不同的控制器:然后在
orders.php
中您将放置您的 < code>vieworders($id) 方法等等,您将能够通过domain.com/sales/orders/vieworders/id
访问它。您还可以在
/models/
和/views/
中创建子文件夹来组织文件。现在,访问控制是不同的,它更多地取决于您正在使用的身份验证系统。
Use folders.
If you make a subfolder in
/application/
calledsales
you can put different controllers in there:Then in
orders.php
you will put yourvieworders($id)
method and so on, and you will be able to acces it withdomain.com/sales/orders/vieworders/id
.You can also make subfolders in the
/models/
and/views/
to organize your files.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.
This would be the exact way i would do it.
看来你应该看看路由类。可能是一个肮脏的解决方案,但将 sales/(:any) 重新路由到 sales_$1 之类的内容意味着您将使用 sales_orders 之类的名称创建控制器。
设计部分也是如此。
(仅供参考:
$routing['sales/(:any)'] = 'sales_$1';
应该可以解决问题;请参阅 application/config/routing.php)。Seems like you should have a look into the routing 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.
Same for the design part.
(FYI:
$routing['sales/(:any)'] = 'sales_$1';
should do the trick; see application/config/routing.php).