Proffer plugin Upload file hasOne

Need help, I can’t see what I’m doing wrong… I’m trying in brand add form to upload a logo image but
with hasOne association I cant make it works.
BrandsTable

$this->hasOne('BrandLogos', [
            'foreignKey' => 'brand_id',
 ]); 

add form brand

echo $this->Form->control('brand_logo', ['label'=>'Logo', 'type'=>'file']);

but if I use hasMany everything work

$this->hasMany('BrandLogos', [
            'foreignKey' => 'brand_id',
 ]); 

add form brand

echo $this->Form->control('brand_logos.0.name', ['label'=>'Logo', 'type'=>'file']);

Thanks for any help…

In the hasOne case the Form::control name (first parameter) would be brand_logos.name.

brand_logos.0.name would be correct for has_many

I have tried that too… :s
debug of patchentity

APP/Controller\Admin\BrandsController.php (line 62)
object(App\Model\Entity\Brand) id:0 {
'name' => 'aaa' 'url' => 'aaa' 'active' => (int) 1 'brand_logos' => [
'name' => object(Laminas\Diactoros\UploadedFile) id:1 { },
] '[new]' => true '[accessible]' => [ ] '[dirty]' => [ ] '[original]' => [ ] '[virtual]' => [ ] '[hasErrors]' => false '[errors]' => [ ] '[invalid]' => [ ] '[repository]' => 'Brands' protected _accessible => [ ] protected _fields => [ ] protected _original => [ ] protected _hidden => [ ] protected _virtual => [ ] protected _dirty => [ ] protected _accessors => [ ] protected _new => true protected _errors => [ ] protected _invalid => [ ] protected _registryAlias => 'Brands'

but nothing in the database and no file uploaded too

Surely brand_logo.name, not brand_logos.name?

2 Likes

with brand_logo.name that doesn’t work too and when I debug patchentity doesn’t show the associated model.
Before asking help I have made a research and found this Upload creating an exception · Issue #239 · davidyell/CakePHP-Proffer · GitHub but the solution given by author of the issue or davidyell doesn’t work for me…

I have found the solution:
My mistake was ‘brand_logos’=>true instead of brand_logo=>true in brand model entity and in the form
like zuluru said is brand_logo.name!
Thank Zuluru and dreamingming for yours helps

1 Like