AddField type image and sketch path

I have a Magento online store and have just created a custom module with the extension (Modulecreator). This module comes with a standard admin interface that can handle file downloads. I found out that if you want to show thumbnails, you can use the type of the image field (addField ('myfield', 'image')) instead of the file type field.

But now I have a problem. When I upload files, I save them in a subdirectory called "slides" in the "media" directory. But when I edit the item, the image path for the thumbnail next to the download field is set to the "media" folder. Not my folder, as I set it to 'media / slides /'.

I am using the following code:

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

I tried to set the key "path" in the array, but Magento does not receive it. I hate the lack of support for good and easy-to-use Magento documentation ...

Maybe you can help me find a solution?

+3
source share
4 answers

another solution is to simply edit your path after calling magento $ form-> setValues ​​(...) basically before returning, do the following:

  $p = $form->getElement('filename')->getValue();
  $form->getElement('filename')->setValue('media/slides' . $p);

.gondo

+3
source

, . , "". /lib/Varien/Data/Form/Element/Image.php. , , - "" :

public function getName()
{
    return  $this->getData('name');
}

, , , , "":

public function getPath()
{
    return  $this->getData('path');
}

, _getUrl(), URL- , ( getPath() '$ this- > getValue()')

protected function _getUrl()
{
    return $this->getPath().$this->getValue();
}

, , . , , ...

+1

, , ;).

. , StackOverflow: .

, ;)

.

0

hmm , magento. Varien_File_Uploader ( ). ( ) ( Post, )

:

$upload = new Varien_File_Uploader($_FILE['custom_image']['name']);
$p = $upload->save('in/to/the/folder');
$data = $this->getRequest()->getPost();
$data['custom_image'] = 'myfolder'. DS .'subfolder'.$p['file'] // path return after save through Varien_File_Uploader.

after the save operation, it will necessarily save the file path information in the corresponding column of the table. Hope this helps.

0
source

Source: https://habr.com/ru/post/1747601/


All Articles