This relates to what is best practice with regards to MVC.
I have a snippet of code which auto-generates an AJAX HTML button which looks up a value from the database and prompts the user to overwrite what is in the current field on their HTML form. The arrangement works. But want to try to follow correct conventions. The parts are:
-
A function which is passed the name of a field and uses CHtml::ajaxButton to return an HTML button. I echo the result on the _form.php view. There is javascript involved and I wanted to reuse the code rather than write it out 10 times separately for each button on the _form.php page. This just generates buttons. (Currently in the model)
-
A function which handles the AJAX request. (Currently in the controller.)
-
A function which (2) looks to to actually get the value from the database. (I split this off an put it into the model)
Question:
i) Model View or Controller for the generate HTML button function? It does not need to be used anywhere else in the app just many times on this one form.
ii) Is there a more elegant way to handle what I have done by splitting the function into 2 parts to handle the AJAX request. This way end up with a very skimpy function in the controller which just asks a function in the model for the value from the database and then displays it as view with no layout for the AJAX. Seems wrong to put it all in the controller.
Thanks for your wisdom if you have any input here.