2

我正在使用magento 1.7这里有一些问题我无法理解我已经创建扩展名并在我选择图像然后保存时在表单中使用图像类型字段成功但是当我编辑并且没有进行更改时点击保存然后我得到了这个以下错误你有什么解决办法吗

Notice: Array to string conversion  in D:\wamp\www\easyshop\lib\Varien\Data\Form\Element\Image.php on line 57

#0 D:\wamp\www\easyshop\lib\Varien\Data\Form\Element\Image.php(57): mageCoreErrorHandler(8, 'Array to string...', 'D:\wamp\www\eas...', 57, Array)
#1 D:\wamp\www\easyshop\app\design\adminhtml\default\default\template\widget\form\renderer\fieldset\element.phtml(40): Varien_Data_Form_Element_Image->getElementHtml()
#2 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(241): include('D:\wamp\www\eas...')
#3 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml\defau...')
#4 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(286): Mage_Core_Block_Template->renderView()
#5 D:\wamp\www\easyshop\app\code\core\Mage\Adminhtml\Block\Template.php(81): Mage_Core_Block_Template->_toHtml()
#6 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(863): Mage_Adminhtml_Block_Template->_toHtml()
#7 D:\wamp\www\easyshop\app\code\core\Mage\Adminhtml\Block\Widget\Form\Renderer\Fieldset\Element.php(52): Mage_Core_Block_Abstract->toHtml()
#8 D:\wamp\www\easyshop\lib\Varien\Data\Form\Element\Abstract.php(223): Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element->render(Object(Varien_Data_Form_Element_Image))
#9 D:\wamp\www\easyshop\lib\Varien\Data\Form\Element\Abstract.php(233): Varien_Data_Form_Element_Abstract->getHtml()
#10 D:\wamp\www\easyshop\lib\Varien\Data\Form\Element\Fieldset.php(90): Varien_Data_Form_Element_Abstract->toHtml()
#11 D:\wamp\www\easyshop\app\design\adminhtml\default\default\template\widget\form\renderer\fieldset.phtml(49): Varien_Data_Form_Element_Fieldset->getChildrenHtml()
#12 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(241): include('D:\wamp\www\eas...')
#13 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml\defau...')
#14 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(286): Mage_Core_Block_Template->renderView()
#15 D:\wamp\www\easyshop\app\code\core\Mage\Adminhtml\Block\Template.php(81): Mage_Core_Block_Template->_toHtml()
#16 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(863): Mage_Adminhtml_Block_Template->_toHtml()
#17 D:\wamp\www\easyshop\app\code\core\Mage\Adminhtml\Block\Widget\Form\Renderer\Fieldset.php(51): Mage_Core_Block_Abstract->toHtml()
#18 D:\wamp\www\easyshop\lib\Varien\Data\Form\Element\Abstract.php(223): Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset->render(Object(Varien_Data_Form_Element_Fieldset))
#19 D:\wamp\www\easyshop\lib\Varien\Data\Form\Element\Abstract.php(233): Varien_Data_Form_Element_Abstract->getHtml()
#20 D:\wamp\www\easyshop\lib\Varien\Data\Form.php(244): Varien_Data_Form_Element_Abstract->toHtml()
#21 D:\wamp\www\easyshop\lib\Varien\Data\Form.php(256): Varien_Data_Form->toHtml()
#22 D:\wamp\www\easyshop\app\code\core\Mage\Adminhtml\Block\Widget\Form.php(108): Varien_Data_Form->getHtml()
#23 D:\wamp\www\easyshop\app\design\adminhtml\default\default\template\widget\form.phtml(28): Mage_Adminhtml_Block_Widget_Form->getFormHtml()
#24 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(241): include('D:\wamp\www\eas...')
#25 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml\defau...')
#26 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(286): Mage_Core_Block_Template->renderView()
#27 D:\wamp\www\easyshop\app\code\core\Mage\Adminhtml\Block\Template.php(81): Mage_Core_Block_Template->_toHtml()
#28 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(863): Mage_Adminhtml_Block_Template->_toHtml()
#29 D:\wamp\www\easyshop\app\code\local\Easyshop\Slider\Block\Adminhtml\Slider\Edit\Tabs.php(19): Mage_Core_Block_Abstract->toHtml()
#30 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(862): Easyshop_Slider_Block_Adminhtml_Slider_Edit_Tabs->_beforeToHtml()
#31 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Text\List.php(43): Mage_Core_Block_Abstract->toHtml()
#32 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(863): Mage_Core_Block_Text_List->_toHtml()
#33 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(582): Mage_Core_Block_Abstract->toHtml()
#34 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(526): Mage_Core_Block_Abstract->_getChildHtml('left', true)
#35 D:\wamp\www\easyshop\app\design\adminhtml\default\default\template\page.phtml(58): Mage_Core_Block_Abstract->getChildHtml('left')
#36 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(241): include('D:\wamp\www\eas...')
#37 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(272): Mage_Core_Block_Template->fetchView('adminhtml\defau...')
#38 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Template.php(286): Mage_Core_Block_Template->renderView()
#39 D:\wamp\www\easyshop\app\code\core\Mage\Adminhtml\Block\Template.php(81): Mage_Core_Block_Template->_toHtml()
#40 D:\wamp\www\easyshop\app\code\core\Mage\Core\Block\Abstract.php(863): Mage_Adminhtml_Block_Template->_toHtml()
#41 D:\wamp\www\easyshop\app\code\core\Mage\Core\Model\Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#42 D:\wamp\www\easyshop\app\code\core\Mage\Core\Controller\Varien\Action.php(390): Mage_Core_Model_Layout->getOutput()
#43 D:\wamp\www\easyshop\app\code\local\Easyshop\Slider\controllers\Adminhtml\SliderController.php(44): Mage_Core_Controller_Varien_Action->renderLayout()
#44 D:\wamp\www\easyshop\app\code\core\Mage\Core\Controller\Varien\Action.php(419): Easyshop_Slider_Adminhtml_SliderController->editAction()
#45 D:\wamp\www\easyshop\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('edit')
#46 D:\wamp\www\easyshop\app\code\core\Mage\Core\Controller\Varien\Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#47 D:\wamp\www\easyshop\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#48 D:\wamp\www\easyshop\app\Mage.php(683): Mage_Core_Model_App->run(Array)
#49 D:\wamp\www\easyshop\index.php(88): Mage::run('', 'store')
#50 {main}

我使用以下代码添加图像类型字段

  $fieldset->addField('filename', 'image', array(
      'label'     => Mage::helper('slider')->__('File'),
      'required'  => false,
      'name'      => 'filename',
  ));

请帮我解决这个问题

4

1 回答 1

3

只需尝试如下代码。因为在编辑模式下,当用户没有对图像进行任何操作时,没有选择删除也没有选择新图像,那么您必须从数据中删除元素,因此 magento 将忽略图像字段,这个问题将得到解决。我有同样的问题,所以在尝试了几次研发后我知道了解决方案

if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
    /* 
        Move uploaded file logic when user select a image
    */
} else {

    if(isset($data['filename']['delete']) && $data['filename']['delete'] == 1) {
        /*
            When user click on checkbox for deletion
        */
        $data['filename'] = '';
    } else {
        /* 
            in edit mode when user nothing did with image not 
            select for deletion nor selected new image then you must 
            be remove element from data so magento will ignore image 
            field and this issue will be resolved
        */
        unset($data['filename']);
    }
}
于 2013-01-04T05:42:55.093 回答