We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Controllers And Subcontrollers - Views and Subviews in Phalcon

Hi,

What I want to do is to have Controllers And Subcontrollers.

I use this structure: https://github.com/phalcon/mvc/tree/master/simple-subcontrollers

The problem for me it is that if in View folder if let's say in views->admin if I put there index.volt and because I have folder users->index.volt when I try to access localhost/myproject/admin I will have there "Admin index" but when I try to access localhost/myproject/admin/users I will have the same "Admin index" instead "Users Index". I need something like this:

localhost/myproject/admin = "Admin index view" localhost/myproject/admin/users = "Users index view"

Is this possible? And let's say in controllers/admin/DashboardController.php if I want to define an action Post then in views dashboard/post/index.volt I go localhost/myproject/dashboard/post here to be "Post Index View" or if I have another action in DashboardController let's say statsAction then to have in views dashboard/stats/index.volt -> DashboardController to be on admin folder in controllers forlder.

Is this possible?



5.7k

Of course, just disable proper view level - https://docs.phalcon.io/pl/latest/reference/views.html#control-rendering-levels

Ok, I know that I can disable a view but in this case how to make this dinamically:

localhost/admin/user/index.volt localhost/admin/index.volt

I need both indexes;

What you mean dynamically? Just in action/initialize of users controller disable view level.



5.7k

What you mean dynamically? Just in action/initialize of users controller disable view level.

I mean, let's say I have this structure:

views->admin(folder)->user(folder)->index.volt and if I have in admin(folder)->index.volt than when I try to access the localhost/admin/user/ than I will have the admin index not the user index, if I delete the admin index than I will have the user index.

I need to be able to access admin index too and user index too.

Then as i wrote above, use disabling levels.