What is the proper way to add an image to an Admin Controller ?



  • I have this module that I made. It works fine, I can create entries and all. But i can’t seem to figure out the proper way to use the tools that AdminController is giving me.

    I tried adding this in my ObjectModel

    'picture' => 		array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => false),
    

    And the field in my inputs list:

    	if ($id_recipe = (int)Tools::getValue('id_recipe'))
    	{
    		$item = $this->loadObject();
    		$file = '../modules/' . $this->name.'/views/img/'. $item->picture.$this->typeImage;
    
    	} else {
    		$file = "";
    	}
    
    
    	$inputs[] = array(
    				'type' => 'file',
    				'label' => $this->l('Image en-tête'),
    				'name' => 'picture',
    				'thumb' => ($file!=""&&file_exists($file)) ? $file : '',
    				'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->tpl_view_vars['object']->id.'&token='.$this->token.'&deleteImage=1',
    			);
    

    Then I tried adding this in my construct:

    	$this->fieldImageSettings = array(
    		'name' => 'picture',
    		'dir' => $this->module
    	);
    	$this->typeImage = 'jpg';
    

    At this very moment, the field does appear in the edit panel of the object…
    I’ve tried looking for tutorials, guides, scoured forums… I’m lost. Why is it so hard?

    PS : Small random question, how do i know which mode i’m in when in renderForm() ?


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.