Vlatko
Vlatko

Reputation: 1385

Prestashop upload field image display

I created new AdminReferenceController in prestashop back office with list and form for every item in list, and everything is working fine except one thing. When i try show image below upload button image is not displayed, (i check, image exist on server and url is valid). I use prestashop 1.5.6.0 Please check what i am doing wrong? Name and description values is properly displayed...

 public function renderForm()
{
    $this->fields_form = array(
        'tinymce' => true,
        'legend' => array(
            'title' => $this->l('Reference'),
            'image' => '../modules/reference/logo.gif'
        ),
        'input' => array(
            array(
                'type' => 'text',
                'lang' => false,
                'label' => $this->l('Reference name:'),
                'name' => 'name',
                'size' => 60,
                'desc' => $this->l('Reference name')
            ),
            array(
                'type' => 'file',
                'lang' => false,
                'label' => $this->l('Reference image:'),
                'name' => 'image',
                'display_image' => true,
                'desc' => $this->l('Upload Reference image from your computer')
            ),
            array(
                'type' => 'textarea',
                'label' => $this->l('Reference description:'),
                'name' => 'description',
                'autoload_rte' => true,
                'desc' => $this->l('Reference description')
            )
        ),
        'submit' => array(
            'title' => $this->l('Save'),
            'class' => 'button'
        )
    );

    if (!($obj = $this->loadObject(true)))
        return;



    $this->fields_value = array(
        'image' => "<img src='/prestashop/img/reference/1.jpg'>",
        'size' =>  '500',
        'name' => 'test',
        'description' => 'test'
    );  

    return parent::renderForm();
}

Thanks

Upvotes: 0

Views: 7256

Answers (1)

Chetan
Chetan

Reputation: 49

You can also use this code if it helps you

 public function renderForm()
    {
            if (!($obj = $this->loadObject(true)))
            return;

                $image = _PS_MANU_IMG_DIR_.$obj->id.'.jpg';
        $image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350,
            $this->imageType, true, true);
        $image_size = file_exists($image) ? filesize($image) / 1000 : false;

        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Add Maker'),
                'icon' => 'icon-maker'
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('Name'),
                    'name' => 'name',
                    'required' => true
                ),
                array(
                    'type' => 'file',
                    'label' => $this->l('Maker Image'),
                    'name' => 'image_url_maker',
                    'image' => $image_url ? $image_url : false,
                    'size' => $image_size,
                    'display_image' => true,
                    'col' => 6,
                    'hint' => $this->l('Upload a maker image from your computer.')
                ),

            ),

            'submit' => array(
                'title' => $this->l('Save'),
            )
        );

        return parent::renderForm();
    }

Upvotes: 4

Related Questions