Kartik Editable Column + File_Input

Hello!

I’m trying to setup a kartik’s Editable Grid column with Editable::INPUT_FILEINPUT widget. For some reason the file upload doesn’t happen.

In the controller action I put the following code




            $tmp = UploadedFile::getInstance($model, 'logo');

            if (empty($tmp)) {

                $tmp = UploadedFile::getInstanceByName('logo');

            }



but $tmp remains empty in any way…

My Editable column config:




                    

                    'editableOptions' => function ($model, $key, $index) {

                        return [

                            'formOptions' => [

                                'action' => ['team/update'],

                                'options' => [

                                    'enctype' => 'multipart/form-data'

                                ],

                            ],

                            'preHeader' => '',

                            'submitButton' => [

                                'icon' => Icon::show('download',['class' => 'text-primary'], Icon::FA)

                            ],

                            'resetButton' => [

                                'icon' => Icon::show('ban',['class' => 'text-danger'], Icon::FA)

                            ],

                            'inputType' => Editable::INPUT_FILEINPUT,

                            'options' => [

                                'options' => ['accept' => 'image/*'],

                                'pluginOptions' => [

                                    'showRemove' => false,

                                    'showUpload' => false,

                                ]

                            ],

                        ];

                    }, 

Is there any specific that needs to be configured in addition?

Did some more investigation. Noted that $_FILES array structure is the following




Array

(

    [TeamCreateEditForm] => [

        

            [name] => [

                    '0' => ['logo' => 'ARI-6.jpg']

                ]


            [type] => [

                    '0' => ['logo' => image/jpeg]

                ]


            [tmp_name] => [

                

                    '0' => ['logo' => 'C:\xampp7\tmp\php323.tmp']

                ]


            [error] => [

                

                    '0' => ['logo' => '0']

                ]


            [size] => [

                

                    '0' => ['logo' => '221913']

                ]


        ]




So guessing that [‘0’ => ‘…’]subarrays are the root cause that UploadFile::getInstance() doesn’t work properly. Any ideas how to workaround it?

UPDATE. Using firebug changed input field Html attributes from


'name' = Team[0][logo]

to


'name' = Team[logo] 

and


'id' = team-0-logo

to


'id' = team-logo

, submitted the form and it worked as expected. Now the question transforms to another one - what should I change in the EditColumn configuration to get rid of this 0 index? (0 is the index of the current GridView line, next is 1, the one after - 2 etc)

UPDATE 2. Found a way to do that… But now the widget works for the first GridView row only. Guess that’s because of non-unique input field ids… So still asking for help…

Check the yii UploadedFile documentation. Treat this like a multiple file upload (even though you get one file record)… so instead of


UploadedFile::getInstanceByName

… use


UploadedFile::getInstancesByName

and you should be able to receive it like an array of files.

but if it is not multiple? :unsure: