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 に答える