开发者

codeigniter extra url segments

开发者 https://www.devze.com 2023-03-19 22:06 出处:网络
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 redire

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 c开发者_如何学运维lass, 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!


Use folders.

If you make a subfolder in /application/ called sales you can put different controllers in there:

/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.

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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号