I have made a custom component using https://www.component-creator.com (which made the process really easy). I have two fields that are only there to serve as sums of the other fields.

At the moment in the views I just do a simply calculation and then set the variable as the answer. This however, does not save it to the database.

It achieves the right results and the user will never know any different, but I was wondering how I could save it to the database. Would I do this as an onAfterSave plugin, or could I do this in the view I am in, or should I do this in the model?

  • Just create a short function if needed in your model to save the result in the db and call that function from your view. It’s usually that simple. If that’s what you are looking for to stay at MVC pattern. – Zollie Jan 28 '19 at 21:04
  • Yeah but I don't want it overridden – Eoin Jan 28 '19 at 21:10
  • Will not it be a new data which should be saved in a new table field as an answer from a user? What could be overriden? I do not get it yet. – Zollie Jan 29 '19 at 4:56

Inside your form model, add save() method. Make any changes you need to data and then call parent method:

public function save($data)
    $data['fieldC'] = $data['fieldA'] + $data['fieldB'];

    return parent::save($data);

You might want to check if specific data fields are defined, as well as cast them as correct type, to avoid warnings.

| improve this answer | |

I'm sorry to not answer your question directly. I just came off Component-Creator.com having terrible experience with them. Mostly because I encountered too many bugs with their system. The big disadvantage is not being able to create a complete component within their system.

I found a hidden gem that I don't want you to miss: www.joomlacomponentbuilder.com

  • It lets you create a full-fledged component and compile it.
  • No customisations after compilation needed.
  • Their support is better than the pricey support at component-creator.com.
  • Best of all -- It's free!

Oh and your problem is a standard feature of JCB. No need to code it in.

| improve this answer | |
  • 1
    Awesome I already knew about this and I just haven't had time to learn it yet. But I also found issues with component component-creator. Even so it's still an awesome tool for rapid development. – Eoin Jan 29 '19 at 23:28
  • 1
    Yeah it took me 4 days to learn and then 2 days to convert my project (12 tables, 150+ fields). to JCB. When i was searching i came across JCB also. And it looked too hard but i regret i didn't try it sooner... Good luck! :) – TLWebdesignNL Jan 29 '19 at 23:53
  • 1
    Thank you. Good tip. I tried it first actually. But then I saw it would take a day at least. Component creator took hours to create my whole component. But definitely moving on next. – Eoin Jan 29 '19 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.