0

我有一个应用程序,我创建了一个带有文件上传的寄存器。好的,文件上传和创建的寄存器很好。

我希望当用户放置文件时,它会进行更新。如果不是,请不要更新包含文件路径的字段。

但是,我需要编辑这个寄存器。编辑时,我的文件上传显示错误:

错误:SQLSTATE [42S22]:未找到列:1054 “字段列表” SQL 查询中的未知列“数组”societario :更新。attorneysSET nome= 'teste editor', empresa= '', filial= '', unidade= 'Energia', alcada= 'Até 10.000', validade= '123123111', arquivo= 数组 WHERE societarioattorneys. id='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'));
    }
}
4

2 回答 2

0
arquivo = Array

它认为 Array 是一个字段...因此,如果您确实希望保存“Array”,则将其放在单引号中。否则我认为你忘记了美元。

编辑-我想我会提到这是在您的 UPDATE 语句中。

于 2013-08-16T15:22:54.557 回答
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'));
    }
}
于 2013-08-16T15:43:07.400 回答