我正在使用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',
));
请帮我解决这个问题
答案 0 :(得分:2)
只需尝试以下代码即可。因为在编辑模式下,当用户没有对图像进行选择而不选择删除也没有选择新图像时,您必须从数据中删除元素,因此magento将忽略图像字段,此问题将得到解决。我有同样的问题,所以我在尝试了几个r& d后知道解决方案
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']);
}
}