CTabView to render a controller/view instead of a view

Hi,

I'm writing an app where we want optional parts of it to be modular, so the user can install extra functionality on the fly.  Adding these items into a navigation menu is fairly easy, however I also thought that if a "module" needs tighter integration into the main app this becomes a problem.  In the example below I already have User Accounts which I would like to optionally extend with User Profiles.  The idea is to retain separation between the two, ultimately allowing different permissions to be applied, allowing system administrators to amend User Accounts, and office administrators to amend User Profiles.

I have tried adding a user profile module to an already existing users table, whereby the primary key of the new table is also now the foreign key of the users table.  In this scenario it would make sense to add this new user profile form as a tab on the existing user form page.  Anybody with permissions can view both tabs, on the same page and update information in either tab.

To facilitate a "module" adding it's own tabs to existing tab bars I thought of using a tab table in the database as follows:

[table]

[tr]

[td]field[/td]

[td]type[/td]

[/tr]

[tr]

[td]id[/td]

[td]PK[/td]

[/tr]

[tr]

[td]name[/td]

[td]tab main name - required[/td]

[/tr]

[tr]

[td]title[/td]

[td]tab item name[/td]

[/tr]

[tr]

[td]weight[/td]

[td]weighting to order by[/td]

[/tr]

[tr]

[td]destination[/td]

[td]the view to be partially rendered into the tab[/td]

[/tr]

[tr]

[td]visible[/td]

[td]NULL is default and means true (visible) - or a php exp​ression to determine visibility[/td]

[/tr][/table]

As you can see if the tabs are generated in a view by reading, for example, all the name=>'users' tabs from the table.  Ordering it correctly, an addon module can easily insert a tab into another pages code - and hence to the user it makes it look very tightly integrated.

The problem comes from this being done at run time, in order to pass the correct model to the user page, and then passed onto the view created by the new tab, the code in the user controller would have to be changed to facilitate this.  This is obviously not desirable as it stops the main point of this functionality whereby we can release a module at a later date and simply add it in, without altering the core code.

The way I could see this working, is if the render partial part of the new tab could go via the new controller for this new module, and hence do the required processing to the new model etc and perform any saving tasks when submitted.

Is it possible to do this?  Or am I completely going about this the wrong way?

Any help would be appreciated!  Another thought would be to have all the processing code going into the view, but that defeats the purpose of MCV.  Sorry for the long-winded question.  If it doesn’t make sense I’m happy to clear up any confusion.

Hi,

i've had the same problem once. I had a form and i used CTabView to switch between different forms belonging to the same "object" (like a user). One of these forms was very specific depending on the type of object and its values and therefore it was decided at runtime which one should be shown without knowing the model etc. at design time.

I also remember that i solved this issue, but later on i changed it to work in an completly different way without any tabs… so i have to search my SVN to find the first solution.

I'll do so maybe this evening or tomorrow.

Regards

Hi,

Thanks for the reply, I currently have this setup working with dynamically created DB tabs now, updating different models, but using the idea I posted, in that some of the control had to go into the view.  Doing that it does seem to work fairly well, though with the obvious down side of it not being in the controller, plus the other in that you can't submit all forms at once in order to save everything on every tab with one click, but that's the side effect of having the freedom to do this stuff at runtime I guess.

I would be very interested to see your solution though, as I'm convinced there's a better way to do this, I'm really not happy with the almost "hack" way of doing it right now, so seeing how you've done it would be very interesting indeed!