3

I'm trying to store multiple field values in a JSON string in my component but I'm not quite sure how to go about it. I've done some research and it seems that using the load and bind JTable methods are the way to go but I don't know how to render the fields on my form and vice versa.

Any tips or advice would be appreciated!

3

You can do it either in your Table class or Model class:

// Convert a JSON field to an array
$registry = new JRegistry;
$registry->loadString($item->jsonfield);
$item->jsonfield = $registry->toArray();

See the reference

And vice versa:

// Convert an array field to a JSON
if (isset($data['jsonfield']) && is_array($data['jsonfield']))
{
    $registry = new JRegistry;
    $registry->loadArray($data['jsonfield']);
    $data['jsonfield'] = (string) $registry;
}

See the reference

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.