0

it will display error if i update other filed and 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 data
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 to 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 for 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 this way do for All Except Image.
}
  //     pr($this->$this->request->data);
    if ($this->Tour->save($this->request->data)) {              
    $this->Session->setFlash(__('Unable to add your schedule.'));

    //Save image
    $this->Session->setFlash(__('Your tour has been updated.'));
    return $this->redirect(array('controller'=>'admin','action' => 'tour'));    
    $this->Session->setFlash(__('Unable to update your Tour.'));
    }
}
$tour = $this->Tour->findByid($id);
if (!$tour) {
    throw new NotFoundException(__('Invalid post'));
}
if (!$this->request->data) {
    $this->request->data = $tour;
}

}

my cont code my view is below. so when i upload image it will work fine. but in edit if i dont upload image then it display array to sting error. means it not take ast image. thanks

echo $this->Form->create('Tour',array('autocomplete' => 'off','enctype'=>'multipart/form-data'));
echo $this->Form->input('varbigimg',array('type' => 'file'));?>
newsurt
  • 43
  • 1
  • 9
  • Can you Please tell WHAT error it gives? – Pratik Joshi Oct 30 '14 at 10:02
  • Notice (8): Array to string conversion [CORE/Cake/Model/Datasource/DboSource.php, line 2061] Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list' `id` = 176, `varbigimg` = Array – newsurt Oct 30 '14 at 10:05

1 Answers1

0

Write Else for

if(is_uploaded_file($this->request->data['Tour']['varbigimg']['tmp_name']))
{
   .........
}else{

     //**TWO GOLDEN LINES OF YOUR LIFE**
     $tourForImg = $this->Tour->findByid($id);
     $this->request->data['Tour']['varbigimg'] = $tourForImg['Tour']['varbigimg'];
     //**TWO GOLDEN LINES OF YOUR LIFE**


     //AS Img not uploaded by user
     //Write All data EXPLICITELY that you want to 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 this way do for All Except Image.



}
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
  • your code is perfect might be i forget ; or i also clear catch and its work fine thanks :) (Y) – newsurt Oct 30 '14 at 11:06
  • its `cache` , NOT `catch` :) – Pratik Joshi Oct 30 '14 at 11:10
  • 1 more question i started admin. and its fine. i used action allow as per my req. in beforfilter . but 1 problem. i block add action but i want to allow only book/add but not other add. so what to do in before filter . is any specific controller/action in before filter. this type support or not / i try but not work.. ! any suggetion.! – newsurt Oct 30 '14 at 11:57
  • @newsurt , In UserController, use beforefilter , Restrict ADD , in OTHER Controller DONT use before filter . ITS simple – Pratik Joshi Oct 30 '14 at 12:10
  • oh wow. actually i put before filter in app cont. but i understand your answer and put add action in controller's before filter. so i access it with out login thanks :) so admin done. thanks thanks. again.:) – newsurt Oct 30 '14 at 12:21
  • @newsurt Welcome again – Pratik Joshi Oct 30 '14 at 12:41
  • i want to add class for session set flash message.. ? is it possibl.e ? want to add my class name = alert alert-success .. itry array. but not update. how to write.plz help thanks $this->Session->setFlash(__('Your home has been updated.')); – newsurt Oct 30 '14 at 13:38
  • I told u if u trust god , god will build CODE for u . Just kidding :) USE in controller -> `$this->Session->setFlash('Message', 'default', array ('class' => 'msgflashSuccess'), 'notificationAdded');` NOW USE in ctp -> echo $this->Session->flash('notificationAdded'); – Pratik Joshi Oct 30 '14 at 13:55
  • thanks. and in edit. plz help me for multiple image. i try it. but same. if i update all 3 images then its work or if i not update all 3 then its work. but what i want. if i update 1 then 1 update other 2 same. if i update 2 then 2 update other 1 same.. ! plz help on it thanks. again :) :) – newsurt Oct 31 '14 at 04:29
  • This is new question , you can post new one. – Pratik Joshi Oct 31 '14 at 04:50
  • ok done. http://stackoverflow.com/questions/26667829/multiple-image-editing-error-in-my-cakephp-project-cakephp2-5 – newsurt Oct 31 '14 at 05:03
  • hi. what if i want to display session setflash message in same page in message box.? thanks.. – newsurt Nov 01 '14 at 07:05
  • use jquery dude , its simple.Use twitter butstrap – Pratik Joshi Nov 02 '14 at 04:32
  • @newsurt , i told u i m in office & i cant check mail . Post another Question – Pratik Joshi Nov 03 '14 at 04:39
  • http://stackoverflow.com/questions/26708131/i-want-text-field-static-value-as-dynamic-in-cakephp-valu1-val2-val1-val2 – newsurt Nov 03 '14 at 05:24