Magento Saving Multiselect Array on Custom Model

点点圈 提交于 2019-12-08 04:46:28

问题


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!!!


回答1:


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)); 
            }
        }   


来源:https://stackoverflow.com/questions/14056140/magento-saving-multiselect-array-on-custom-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!