This is my situation: I have a single view (lets call it view V) with a formform with multiple combo box for selecting some parameters.
I want to load the options of those combo box via AJAX calls dynamically (selecting one item on a combobox will load the other ones with data)
Each combobox makes an AJAX request to a different controller (which in turn call on different models to fetch the data) on the framework. Lets call those controllers C1, C2, C3 and the models M1, M2, M3.
These AJAX scripts on C1, C2 and C3 are very likely to be used on other views on the future
But i have my doubts if this is the correct way to go. Where do i put those AJAX scripts? On each controller or a separate one (probably called FormAPI or something like that)
Putting one ajax script on each controller i am coupling V with C1, C2 and C3, while making one controller for the three requests will only couple my view V with one controller. Also, from my point of view, such controller will be highly cohesive.
However, i am probably not keeping my code DRY because C1, C2 and C3 already have some logic to recieve requests of the type "get list of M1, M2 and M3", which i could render as JSON and return it to the view V
What happens in the future if i have another view V2 that needs requests to C1, C2, C3, ... CN? I think soon my code will be "spaghetti coupled"
What do you think?
Another question: Should i have logic on M1, M2, M3 to get arrays and lists of items? For instance, if M1 has multiple instances of M2, is it correct to create a method M1->getM2asArray()