Reusing actions and views

I must implement a wizard to show some forms when a user first login in the system. These actions and views are reused when users want to modify some data in their profile.

I cannot call runAction to ProfileController from WizardController actions because layouts are different and return pages are also different (when in ProfileController I redirect to index page when submit is ok and I should redirect to news step in WizardControler). I must use also different actions from different controllers, not just ProfileController…

I don’t know whats the best option to achieve this… I don’t see a component, module or widget as a solution to this. I don’t know if there’s some kind of structure or something to achieve this without a c&p of the code.

Hi ker,

I think that you should not try to reuse the code in the controller/action layer in this case. You would be better considering the following:

  1. You can render a view within another view.

Guide > View > Rendering in Views (https://www.yiiframework.com/doc/guide/2.0/en/structure-views#rendering-in-views)

It means that you can write a commonly used sub-view which can be rendered both in the wizard page and in the profile page.

  1. And the business logic of the profile should be implemented in the model layer.