CakePHP-Proffer icon indicating copy to clipboard operation
CakePHP-Proffer copied to clipboard

Can't upload from another controller

Open koffisani opened this issue 7 years ago • 3 comments

I'm trying to upload a file in related table's controller, but it doesn't work. Can somebody help me make this work ?

koffisani avatar Apr 05 '18 17:04 koffisani

Please can you expand your question with more information? Where have you configured the behavior?

davidyell avatar Apr 06 '18 08:04 davidyell

Thanks, I have the following :

class EvenementsTable extends Table {
    public function initialize(array $config)
    {
        $this->hasMany('Valeurevents', [
            'foreignKey' => 'evenement_id'
         ]);
    }
}

and

class ValeureventsTable extends Table {
    public function initialize(array $config)
    {
        $this->belongsTo('Evenements', [
            'foreignKey' => 'evenement_id',
            'joinType' => 'INNER'
         ]);
         $this->addBehavior('Proffer.Proffer', [
            'fichier' => [
                'root' => WWW_ROOT . 'uploads',
                'dir' => 'fichier_dir',
            ],
        ]);
    }
}

The valeurevents table's tructure is the following :

valeurevents type
content varchar(255)
evenement_id int
fichier varchar(255)
fichier_dir varchar(255)

And now I'm trying to upload the file from EvenementsContoller, what doesn't work.

koffisani avatar Apr 06 '18 10:04 koffisani

Perhaps you need to save the associations as well?

You can read more about this in the book. https://book.cakephp.org/3.0/en/orm/saving-data.html#saving-hasmany-associations

davidyell avatar Apr 18 '18 09:04 davidyell