Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Can't upload from another controller #255

Open
koffisani opened this issue Apr 5, 2018 · 3 comments
Open

Can't upload from another controller #255

koffisani opened this issue Apr 5, 2018 · 3 comments
Labels

Comments

@koffisani
Copy link

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
Copy link
Owner

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

@koffisani
Copy link
Author

koffisani commented Apr 6, 2018

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
Copy link
Owner

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants