如何在ZF 2中返回文件路径

时间:2013-07-11 15:45:18

标签: zend-framework2

我有一个表单和一个控制器ZF 2.我可以上传文件和其他数据,但我不能将文件路径@的@value写入数据库表作为字段的值。仅在表数据库字段中显示值Array!如何更改控制器或其他位置并将文件路径的值保存在表的字段中? 的 RestaurantController.php

 $form = new RestaurantForm();

        $form->get('submit')->setValue('Добавить ресторан');

        $request = $this->getRequest();
        if ($request->isPost()) {
            $restaurants = new Restaurant();
            $form->setInputFilter($restaurants->getInputFilter());

            $data= array_merge_recursive(


                $this->getRequest()->getPost()->toArray(),
                $this->getRequest()->getFiles()->toArray()
            );

            $form->setData($data);
            if ($form->isValid()){
                //array_map('unlink', glob('./public/img/restaurants*'));{
                $restaurants->exchangeArray($form->getData());
                $this->getRestaurantsTable()->saveRestaurant($restaurants);

                // Form is valid, save the form!

                // Redirect to list of albums
                return $this->redirect()->toRoute('zfcadmin/restaurants');
            }


        }
       //else return $this->redirect()->toRoute('zfcadmin');
        return array('form' => $form);
    }

RestaurantForm.php

           // File Input
            $file = new Element\File('restaurant_thumbnail');
            $file->setLabel('Загрузите главный рисунок ресторана')
                 ->setAttribute('id', 'image-file');
            $this->add($file);

Restaurant.php

                    #version2
                  //  $inputFilter = new InputFilter();

                    // File Input
                    //https://github.com/cgmartin/ZF2FileUploadExamples/blob/master/src/ZF2FileUploadExamples/Form/SingleUpload.php
                    $file = new FileInput('restaurant_thumbnail');
                    $file->setRequired(true);
                    $file->getFilterChain()->attachByName(
                        'filerenameupload',
                        array(
                            'target'          => './public/img/restaurants/*',
                            'overwrite'       => true,
                            'use_upload_name' => true,
                        )
                    );
                    $inputFilter->add($file);

0 个答案:

没有答案