2013-08-16 31 views
0

我有一個應用程序,我創建了一個帶有文件上傳的註冊表。好吧,文件上傳和創建的寄存器沒問題。用表單上傳字段編輯註冊表

我希望當用戶把一個文件,它會做更新。如果沒有,請不要更新包含文件路徑的字段。

但是,我需要編輯這個寄存器。 edditing時,我的文件上傳顯示一個錯誤:在 '字段列表' SQL查詢1054未知列 '陣':UPDATE societario

錯誤:SQLSTATE [42S22]:列未找到。 attorneys SET nome = '睾丸中editar',empresa = '',filial = '',unidade = '能源公司',alcada = 'ATE 10.000',validade = '123123111',arquivo =陣列,其中societarioattorneysid = '83'

我的創建控制器:

if($this->request->is('post')){ 

$targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root 
$tempFile = $this->request->data['Attorney']['arquivo']['tmp_name']; 
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
$targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];; 
     move_uploaded_file($tempFile,$targetFile); 


     $this->Attorney->saveAll($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status'))); 
     $this->Attorney->updateAll(
array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",), 
array('id' => $this->Attorney->id)); 

我的編輯控制器:

編輯:修改的編輯控制。解決方案的答案如下。

$this->Attorney->id = $id; 
    $this->set('poderes',$this->Attorney->Power->find('list', array('fields' => 'resumo'))); 

     if ($this->request->is('get')) { 
      $this->request->data = $this->Attorney->read(); 
     } else { 

      if ($this->Attorney->save($this->request->data)) { 


      $this->Session->setFlash('Usuário editado com sucesso!', 'default', array('class' => 'flash_sucess')); 
      $this->redirect(array('action' => 'usuarios')); 
    } 
} 
+0

需要創建或編輯? –

+0

那麼,因爲你得到的錯誤信息是在更新.... – andrewsi

回答

0

我找到了解決方案!感謝

我的編輯器:

$this->Attorney->id = $id; 
    $this->set('poderes',$this->Attorney->Power->find('list', array('fields' => 'resumo'))); 

     if ($this->request->is('get')) { 
      $this->request->data = $this->Attorney->read(); 

     } else { 

      if ($this->Attorney->save($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status')))) { 

      if(!empty($this->request->data['Attorney']['arquivo']['name'])) { 

       $targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root 
       $tempFile = $this->request->data['Attorney']['arquivo']['tmp_name']; 
       $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
       $targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];; 
       move_uploaded_file($tempFile,$targetFile); 

       $this->Attorney->updateAll(
       array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",), 
       array('id' => $this->Attorney->id)); 
       $this->Session->setFlash('procuração editada com sucesso!', 'default', array('class' => 'flash_sucess')); 
      $this->redirect(array('action' => 'usuarios')); 
      } 
      $this->Session->setFlash('Usuário editado com sucesso!', 'default', array('class' => 'flash_sucess')); 
      $this->redirect(array('action' => 'usuarios')); 
    } 
} 
0
arquivo = Array 

它認爲陣列是一種場......所以,如果你從字面上想要的「陣列」保存,然後把它放在單引號。否則,我認爲你忘了$。

編輯 - 以爲我會提到這是你的UPDATE語句。

+0

我找到了解決方案。謝謝 –