我有一个表格和一个控制器ZF 2。我可以上传文件和其他数据,但我不能将文件的路径@的@value写入数据库表作为字段的值。只显示表数据库字段中的值数组!如何更改控制器或其他地方并将文件路径的值而不是数组保存在表的字段中?
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);
餐厅.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);