joomlajoomla2.5joomla3.1

How to override save() method in a component


Where and how I am overriding the save method in Joomla 3.0 custom component ?

Current situation:

Custom administrator component.

I have a list view that displays all people stored in table. Clicking on one entry I get to the detailed view where a form is loaded and it's fields can be edited.

On save, the values are stored in the database. This all works fine.However, ....

When hitting save I wish to modify a field before storing it into the database. How do I override the save function and where? I have been searching this forum and googled quiet a bit to find ways to implement this. Anyone who give me a simple example or point me into the right direction ?

Thanks.


Solution

  • You can use the prepareTable function in the model file (administrator/components/yourComponent/models/yourComponent.php)

    protected function prepareTable($table)
    {
        $table->fieldname = newvalue;
    }