How to organize multi-level MVC application

Asked

Viewed 94 times

0

I am developing an application following the MVC standard, and will have 2 levels of users, the normal and the admin, as regards the options of what each user can do, it is better to make a logic in the controller to show certain view or some action of another controller or create some "if blocks" in a default view to "hide" admin menus only or vice/versa?

Case study:

A normal user accesses Dashboard after login, the ideal would be show a view (views/user_normal) specific to him, who only has the menus/links of his level, or use a view (views/all_users) for both levels and hide menus/links validated?

2 answers

1

A controller can have N views. If you think a view is best for each case (normal user and admin), it’s no problem. But it doesn’t matter if you use a single view with conditional or multiple views. I particularly prefer separate views if there are too many conditionals.

There are those who prefer a strict standard, IE, no matter if it has only 1 conditional, must follow the pattern of multiple views.

Who sets the default is the project manager.

1

To get away from (if/elses) unnecessary by the controller, I’d rather do the way you quoted:

view/user_normal

view/user_differentiated

It’s a matter of good code practice, but in this case, it’s personal to me who’s developing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.