Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kossa's avatar
Level 20

Architecture Question - One view for multi roles

Hi, I'm working on big project with roles and views, in my description I'll make it easy to understand.

So I have :

Tables: "articles", "users", "categories"

Relations :

  1. "articles" and "users" => one to many
  2. "users" and "categories" => many to many
  3. "articles", "categories" => one to many

In users table I have 3 roles :

  1. Admin : Can do everything
  2. Editor : he can CRUD in articles table if he hasn't categories, otherwise he can CRUD only in articles of his categories
  3. Contributor : only CRUD on his article, and add articles in his categories

My Question, what's the best pratise to organise:

  1. Routes (ex. one for admin, and one for editor and contributor)
  2. Controllers (ex. one controller for all users)
  3. Views (ex. one view for displaying list of articles, 2 views for create and edit )

Many thanks :D

0 likes
3 replies
zachleigh's avatar
Level 47

For routes, you're probably only going to want one per route. Same for controllers...one controller for articles, one for users, articles etc. Within your controllers and views, you can then use Auth to get the authenticated user, find their role, and do whatever you need to do for them like toggle buttons, get content from the database or whatever else you need to do.

For views, I would start with separate views for each route, but youll find that there may be a lot of common code in them. The create and edit views, for example, will probably have a lot of the same form pieces. In these cases, extract the common code out to a partial template to save yourself some time and make it easier to change in the future.

1 like
kossa's avatar
Level 20

@Prez, you're right, the only problem is you'll copy/paste a lot of code, hard to make updates, you should do it for others :p

Please or to participate in this conversation.