davidyell / CakePHP-Proffer

An upload plugin for CakePHP 3
MIT License
117 stars 63 forks source link

Can't upload from another controller #255

Open koffisani opened 6 years ago

koffisani commented 6 years ago

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

davidyell commented 6 years ago

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

koffisani commented 6 years ago

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.

davidyell commented 6 years ago

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