Jump to content

Object Model, upload an image


Recommended Posts

Hello !

I am trying to edit a module who use object model for his data.

I just want to add an image field !

 

SQL :

    `monimage` varchar(128) DEFAULT NULL,

Class ObjectModel :

class ExtraContent extends ObjectModel
{
    /**
     * @see ObjectModel::$definition
     */
    public static $definition = array(
        'table' => 'extra_content',
        'primary' => 'id_extra_content',
        'multilang' => true,
        'fields' => array(
            'position' => array('type' => 1 /*self::TYPE_INT*/),
            'move_per' => array('type' => 1 /*self::TYPE_INT*/),
            'active' => array('type' => 2 /*self::TYPE_BOOL*/),
            'tinymce' => array('type' => 2 /*self::TYPE_BOOL*/),
            'hooks' => array('type' => 3 /*self::TYPE_STRING*/, 'required' => true),
            'pages' => array('type' => 3 /*self::TYPE_STRING*/),
            'products' => array('type' => 3 /*self::TYPE_STRING*/),
            'categories' => array('type' => 3 /*self::TYPE_STRING*/),
            'cms' => array('type' => 3 /*self::TYPE_STRING*/),
            'manufacturers' => array('type' => 3 /*self::TYPE_STRING*/),
            'title' => array('type' => 3 /*self::TYPE_STRING*/, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
            'classel' => array('type' => 3 /*self::TYPE_STRING*/, 'validate' => 'isGenericName', 'size' => 128),
            'monimage' => array('type' => 3 /*self::TYPE_STRING*/, 'validate' => 'isFileName'),
            'content' => array('type' => 6 /*self::TYPE_HTML*/, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999),
        ),
    );
    public $id;
    public $id_extra_content;
    public $position;
    public $move_per;
    public $active;
    public $tinymce;
    public $hooks;
    public $pages;
    public $products;
    public $categories;
    public $cms;
    public $manufacturers;
    public $title;
    public $classel;
    public $monimage;
    public $content;
    protected $table = 'extra_content';
    protected $tables = array('extra_content', 'extra_content_lang');
    protected $identifier = 'id_extra_content';
    protected $fieldsRequired = array();
    protected $fieldsValidate = array('position' => 'isUnsignedInt', 'move_per' => 'isInt',);
    protected $fieldsRequiredLang = array('title');
    protected $fieldsSizeLang = array('title' => 128, 'content' => 3999999999999);
    protected $fieldsValidateLang = array('title' => 'isGenericName', 'content' => 'isString');

    [...]

    public function getFields()
    {
        parent::validateFields();

        $fields = parent::getFields();

//      $fields['id_shop'] = (int)($this->id_shop);
        $fields['active'] = (int)$this->active;
        $fields['tinymce'] = (int)$this->tinymce;
        $fields['position'] = (int)$this->position;
        $fields['move_per'] = (int)$this->move_per;
        $fields['classel'] = pSQL($this->classel);
        $fields['monimage'] = pSQL($this->monimage);
        $fields['hooks'] = pSQL(implode(',', $this->hooks));
        $fields['pages'] = pSQL(implode(',', $this->pages));
        $fields['products'] = pSQL(implode(',', $this->products));
        $fields['categories'] = pSQL(implode(',', $this->categories));
        $fields['cms'] = pSQL(implode(',', $this->cms));
        $fields['manufacturers'] = pSQL(implode(',', $this->manufacturers));

        return $fields;
    }

   [...]

    public function add($autodate = true, $null_values = false)
    {
        unset($null_values);
        $this->position = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.$this->table.'`');
        return parent::add($autodate, true);
    }

    public function update($null_values = false)
    {
        $result = parent::update($null_values);
        if ($result) {
            $this->cleanPositions();
        }
        return $result;
    }

    public function delete()
    {
        $result = parent::delete();
        if ($result) {
            $this->cleanPositions();
        }
        return $result;
    }

    [...]
}

Admin Controller :

[...]
       
                array(
					'type' => 'file',
					'label' => $this->l('Image'),
					'name' => 'monimage'
                ),
                
[...]
        return parent::renderForm();

    }

But... nothing.

My image name isn't even saved in database.

 

Any help ? I can upload all file code if needed.

Thanks !

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More