magento Edit Custom Module Image Shows Error

0

Magento Custom module saveAction is working Fine below code I used

public function saveAction()
    {
        if ( $this->getRequest()->getPost() ) {
            try {
                $postData = $this->getRequest()->getPost();
                $uploader = new Varien_File_Uploader('imageurl');
                $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); // Your Format Here
                $uploader->setAllowRenameFiles(true);
                $uploader->setFilesDispersion(false);
                $path = Mage::getBaseDir('media').DS.'Gallery'.DS;                
                $img = $path. $_FILES['imageurl']['name'];
                $filename = $uploader->getNewFileName($img);
                $uploader->save($path, $filename);
                $galleryModel = Mage::getModel('gallery/gallery');                
                $galleryModel->setId($this->getRequest()->getParam('id'))
                    ->setTitle($postData['title'])
                    ->setDescription($postData['description'])
                    ->setStatus($postData['status'])
                    ->setImageurl($filename)
                    ->save();
                //var_dump($uploader);exit();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
                Mage::getSingleton('adminhtml/session')->setgalleryData(false);

                $this->_redirect('*/*/');
                return;
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                Mage::getSingleton('adminhtml/session')->setgalleryData($this->getRequest()->getPost());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                return;
            }
        }
        $this->_redirect('*/*/');
    }

But Edit it’s not working.

public function editAction()
    {
        $galleryId     = $this->getRequest()->getParam('id');
        $galleryModel  = Mage::getModel('gallery/gallery')->load($galleryId);

        if ($galleryModel->getId() || $galleryId == 0) {

            Mage::register('gallery_data', $galleryModel);


            $this->loadLayout();
            $this->_setActiveMenu('gallery/items');

            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));

            $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

            $this->_addContent($this->getLayout()->createBlock('gallery/adminhtml_gallery_edit'))
                 ->_addLeft($this->getLayout()->createBlock('gallery/adminhtml_gallery_edit_tabs'));

            $this->renderLayout();
        } else {
            Mage::getSingleton('adminhtml/session')->addError(Mage::helper('gallery')->__('Item does not exist'));
            $this->_redirect('*/*/');
        }
    }

enter image description here

Also my image not showing in Edit Form .

I stored my Image in media/gallery
but if i check image source it will like this
localhost/project/media/image.png but it should be like this localhost/project/media/Gallery/image.png How i change this?

Link: magento Edit Custom Module Image Shows Error
Source: Stack Magento

Share.

About Author

Leave A Reply