CakePHP 2.6
php 5.6
プラグインのuploadpackを使って画像のアップロードの処理を
実装したいと思い下記のサイトを参考にして実装しました。
http://www.kaasan.info/archives/2482
基本的な機能に関しては、実装できました。
ファイルのアップロードをして、表示させるというところまでは。
しかし、更新した内容を編集するとなぜか。
全く新しいデータが追加されます。
ーーーーーーーーーーーーーーーーーーーーーーーー
コントローラー
public function edit($id = null) { if (!$this->Cosme->exists($id)) { throw new NotFoundException(__('Invalid cosme')); } if ($this->request->is(array('post', 'put'))) { if ($this->Cosme->save($this->request->data)) { $this->Session->setFlash(__('The cosme has been saved.')); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The cosme could not be saved. Please, try again.')); } } else { $options = array('conditions' => array('Cosme.' . $this->Cosme->primaryKey => $id)); $this->request->data = $this->Cosme->find('first', $options); }
モデル
public $actsAs = array('Search.Searchable', 'UploadPack.Upload' => array( 'img01' => array( //'default_url' => 'path/to/default/image',//画像がないファイルはここのパス画像を表示 //'resizeToMaxWidth' => true,//widthが広い画像はリサイズしてアップロード 'quality' => 70,//画像の質 100がMAX 'path' => ':webroot/upload/cosmes/:id.:extension',//画像の保存フォルダ名 'styles' => array( 'big' => '300×300', 'small' => '[100×80]', 'thumb' => '80I', ) ) ), ); public $validate = array( 'img01' => array( 'rule' => array('attachmentContentType', array('image/jpeg', 'image/gif','image/png')), 'message' => 'jpgとgifとpngファイルのみアップロードできます。' ) );
edit
<div class="container"> <div class="row"> <div class="cosmes form"> <?php echo $this->Form->create('Cosme',array('type' => 'file', 'inputDefaults' => array( 'div' => 'form-group', 'wrapInput' => false, 'class' => 'form-control' ), 'class' => 'well' ));?> <fieldset> <legend><?php echo __('Edit Cosme'); ?></legend> <?php echo $this->Form->input('title'); echo $this->Form->input('body01'); echo $this->Form->file('Cosme.img01'); echo $this->Form->error('Cosme.img01'); echo $this->Form->input('body02'); echo $this->Form->input('body03'); echo $this->Form->input('rule'); echo $this->Form->input('kodawari'); echo $this->Form->input('store'); echo $this->Form->input('category_id'); ?> </fieldset> <?php echo $this->Form->end(__('Submit')); ?> </div> </div> </div>
なにが原因なのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/26 09:46