로그인 한 사용 ID를 기반으로 사용자 테이블에 사진 이름과 사진 디렉토리를 저장할 수 없습니다. 기존 사용자 기반의 사용자 사진을 업로드하려고합니다. 기존 사용자의 사진 필드가 업데이트되지 않습니다. 이 플러그인 josegonzalez를 사용하여 사진을 업로드하려고합니다. 도와주세요.Cakephp 3.3 - 플러그인 josegonzalez를 사용하여 이미지를 저장할 수 없습니다
<?php echo $this->Form->create($user, ['type' => 'file']); ?>
<?php echo $this->Form->input('photo',['type' => 'file', 'class' => 'form-control']); ?>
<?php echo $this->Form->input('photo_dir', ['type' => 'hidden']); ?>
<?php echo $this->Form->button(__('Submit'), ['type'=>'submit','class' => 'btn btn-success']); ?>
<?php echo $this->Form->end(); ?>
UsersTable
$this->addBehavior('Josegonzalez/Upload.Upload', [
'photo' => [
'fields' => [
// if these fields or their defaults exist
// the values will be set.
'dir' => 'photo_dir', // defaults to `dir`
],
],
]);
UsersController/add
public function add($id=null)
{
if ($this->request->is('post')) {
if (!$id) {
$id = $this->Auth->user('id');
}
$user = $this->Users->get($id);
$fileName = $this->request->data['photo']['name'];
$user->photo = $fileName;
//$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('Your photo has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Unable to add your photo.'));
}
$this->set('user', $user);
}
php echo $ this-> Form-> create ($ user, [ 'type'=> 'file']); ?> enctype을 생성합니다. – Aarrbee
예. 시도했습니다. 감사! 하지만 작동하지 않았다. – Mythri
컨트롤러에 this-> request-> data의 디버그를 게시 할 수 있습니까? 더 많은 것을 이해하는 데 도움이 될 것입니다. – Aarrbee