1
votes

I have create a custom model in Magento which can get to and edit in the admin. I'm having trouble dealing with array's however. When I go to save the model, the text field saves fine, but the multiselect field just saves as 'array' and I'm then unable to go and edit it.

I need to know how to save and retrieve this array data within the model. The array of data that shows in the multiselect field in simply filtered product data.

Can anybody help with this? Any help much appreciated!!!

enter image description here

1
You can save them with comma separated in database and while retrieving then can be split on comma. - MagentoDiary
Yes that's what I thought. I'm not entirely sure of the best way of doing that.... is it in the Save action of my controller? - Adam Moss

1 Answers

6
votes

Figured it out - on the saveAction() of your controller, underneath this:

$data = $this->getRequest()->getPost()

I simply added the following code :

foreach ($data as $key => $value)
        {
            if (is_array($value))
            {
                $data[$key] = implode(',',$this->getRequest()->getParam($key)); 
            }
        }