Monday, 15 April 2013

if i upload image then edit work fine but if i update other field and not image that time it display array to sting erro in cakephp2.4.5 -



if i upload image then edit work fine but if i update other field and not image that time it display array to sting erro in cakephp2.4.5 -

it display error if update other filed , not image.

public function edit($id = null) { $this->helpers = array('tinymce.tinymce'); $this->layout = 'adminpanel'; if (!$id) { throw new notfoundexception(__('invalid post')); } $this->layout = 'adminpanel'; //save info if ($this->request->is(array('post', 'put'))) { $this->tour->id = $id; //save image if(is_uploaded_file($this->request->data['tour']['varbigimg']['tmp_name'])) { $filenamefull = $this->request->data['tour']['varbigimg']['name']; $uploadfolder = "upload"; //full path upload folder $uploadpath = www_root . $uploadfolder; $oldfile = $uploadpath.'/'.$filenamefull; move_uploaded_file( $this->request->data['tour']['varbigimg']['tmp_name'],$oldfile ); $newfile = www_root.'courseimages/thumb/'.$filenamefull; $image = new imageresizecomponent(); $quality = 100; // image resize thumb $height = 40; $width = 60; $this->imageresize->resize($oldfile, $newfile, 60,60,$quality); $this->request->data['tour']['varbigimg'] = $filenamefull; } else{//img not uploaded $this->request->data['tour']['vartitle']= $this->data['tour']['vartitle']; $this->request->data['tour']['varsubtitle']= $this->data['tour']['varsubtitle']; $this->request->data['tour']['txtsortdesc']= $this->data['tour']['txtsortdesc']; $this->request->data['tour']['txtdeasc']= $this->data['tour']['txtdeasc']; $this->request->data['tour']['vardeparts']= $this->data['tour']['vardeparts']; $this->request->data['tour']['decadultprice']= $this->data['tour']['decadultprice']; $this->request->data['tour']['decchildprice']= $this->data['tour']['decchildprice']; $this->request->data['tour']['varimgtitle']= $this->data['tour']['varimgtitle']; $this->request->data['tour']['enumstatus']= $this->data['tour']['enumstatus']; $this->request->data['tour']['id']= $this->data['tour']['id']; //in way except image. } // pr($this->$this->request->data); if ($this->tour->save($this->request->data)) { $this->session->setflash(__('unable add together schedule.')); //save image $this->session->setflash(__('your tour has been updated.')); homecoming $this->redirect(array('controller'=>'admin','action' => 'tour')); $this->session->setflash(__('unable update tour.')); } } $tour = $this->tour->findbyid($id); if (!$tour) { throw new notfoundexception(__('invalid post')); } if (!$this->request->data) { $this->request->data = $tour; }

}

my cont code view below. when upload image work fine. in edit if dont upload image display array sting error. means not take ast image.

echo $this->form->create('tour',array('autocomplete' => 'off','enctype'=>'multipart/form-data')); echo $this->form->input('varbigimg',array('type' => 'file'));?>

write else for

if(is_uploaded_file($this->request->data['tour']['varbigimg']['tmp_name'])) { ......... }else{ //**two golden lines of life** $tourforimg = $this->tour->findbyid($id); $this->request->data['tour']['varbigimg'] = $tourforimg['tour']['varbigimg']; //**two golden lines of life** //as img not uploaded user //write info explicitely want save without image. $this->request->data['tour']['tourname']= $this->data['tour']['tourname']; $this->request->data['tour']['yourformfield1']= $this->data['tour']['yourformfield1']; $this->request->data['tour']['yourformfield2']= $this->data['tour']['yourformfield2']; //in way except image. }

edit image-uploading cakephp-2.5

No comments:

Post a Comment