Phalcon: View Structure for Multiple Roles

Hi. I have a project, where users have multiple roles:

define ('GUEST',0); define ('ADMIN',1); define ('PRO',2);

Depending on the role, I want to pull a different view in some cases. I'm wondering the best way to structure the folder/files for the views.

Should each role have a folder, and I look to see if the view exists/if not go to the next role? Or do I do this with file names ->index_admin.volt, index_pro.volt? What's the best practice for Phalcon here?

edited 10d ago

Hi. I would do that:

index.volt - you may have some things in common?

/partials - folder with included files for every role - pro.volt, admin.volt and etc.

The individual parts will be included in index.volt. according to the conditions

I dоn't know if this is good practice, however :).

My approach would be to have individual files for each role, stored in a directory based on the action. Something like


Then in your controller, you pick() the appropriate view based on the role of the user.

In the past I've put the logic in the view like:

{% if User.role == const('GUEST') %}
{% else %}

But I think that's not appropriate logic for the view as it seems out of scope for what the view should be doing. I think the best place for that logic is in the controller, which has more awareness of the state of the application.