У меня возникли проблемы с формой, и это сводит меня с ума.«Уведомление: преобразование строки в строку» в CakePHP при загрузке файла
Всякий раз, когда я пытаюсь загрузить изображение в моей базе данных, я получаю
Notice: Array to string conversion [CORE\Cake\Model\Datasource\DboSource.php, line 1009]
Я не уверен, что я делаю неправильно или отсутствует. Любая помощь приветствуется.
Это моя модель
'banner_image' => array(
'not_required' => array(
'allowEmpty' => true,
'required' => false,
),
'is_image' => array(
'rule' => 'is_image_check',
'message' => 'We found that the file you uploaded is not an image.',
//'allowEmpty' => false,
'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
Это мой контроллер
/**
* admin_add method
*
* @return void
*/
public function admin_add() {
if ($this->request->is('post')) {
$this->Survey->create();
if ($this->Survey->save($this->request->data)) {
$this->Session->setFlash(__('The survey has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The survey could not be saved. Please, try again.'));
}
}
}
и это моя форма
<?php echo $this->Form->create('Survey', array('type'=>'file')); ?>
<fieldset>
<legend><?php echo __('Admin Add Survey'); ?></legend>
<?php
echo $this->Form->input('title');
echo $this->Form->input('subtitle');
if (empty($this->request->data['Survey']['banner_image']) or isset($this->validationErrors['Survey']['banner_image'])):
echo $this->Form->input('banner_image', array('type'=>'file'));
else :
echo $this->Html->image('/img/surveys/' . $this->request->data['Survey']['banner_image']) ;
echo $this->Html->link('Remove this image?', '/admin/Surveys/remove_image/' . $this->request->data['Survey']['id']) ;
endif;
// echo $this->Form->input('listing_image', array('type'=>'file'));
echo $this->Form->input('url_iframe');
echo $this->Form->input('enable');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
Когда вы размещаете форму, 'banner_image' не будет содержать содержимое файла. Он будет содержать «загруженный массив информации о файлах». Вы можете прочитать об этом здесь: [POST method uploads] (http://php.net/manual/en/features.file-upload.post-method.php) – user3082321
Всегда указывайте свою версию _exact_ CakePHP и помечайте свой вопрос соответственно - благодаря! – ndm
@ user3082321 Спасибо за ссылку. Это было хорошо прочитано. – robb