How do you manage web navigation info in your application?
I’m building an application where different users开发者_高级运维 will have different menu items available to them depending on what they’ve paid for. There will also be multiple levels to the menu hierarchy.
What’s the best approach to this problem?
I’m assuming I need a database table that represents the menu hierarchy, including the parent-child relationships of the nodes in the navigation as well as the sorting of the items. Then another table which I use to manage whether a user is authorized to access a particular item in that table.
When I render the view, I’d reference the menus, and the access rights of the user to output the menu, and I’d also need a function to check that same authorization from each controller in case a user manually types in a URL of a controller they’re not supposed to have access to.
Is this the right approach? Any suggestions for caching this to prevent the constant look-ups of this type of info? I’m open to any suggestions on how you may have approached this type of requirement.
When a user logs in, I would check all the rights that have then, then store them into their session. This way, you only have to look them up from the database once.
Otherwise, your approach of handling the menu, and in each controller page, seems fine.
精彩评论