我有一个表单和一个控制器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);