Magento Saving Multiselect Array on Custom Model

2019-06-04 22:24发布

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条回答
在下西门庆
2楼-- · 2019-06-04 23:04

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)); 
            }
        }   
查看更多
登录 后发表回答