SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'数组'

时间:2014-03-05 09:20:29

标签: cakephp

<?php

class CarrierController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');


    var $uses=array('Carrier');
    public function index(){
    //  $this->set('posts', $this->carrier->find('all'));
        if($this->request->is('post')){
             Configure::read();
        pr($this->data); 
            $this->Carrier->create();
            $filename = null;

if (
    !empty($this->request->data['Carrier']['Resume']['tmp_name'])
    && is_uploaded_file($this->request->data['Carrier']['Resume']['tmp_name'])
) {
    // Strip path information
    $filename = basename($this->request->data['Carrier']['Resume']['name']); 
    move_uploaded_file(
        $this->data['Carrier']['Resume']['tmp_name'],
        WWW_ROOT . DS . 'documents' . DS . $filename
    );
}

// Set the file-name only to save in the database
$this->data['Carrier']['Resume'] = $filename;
  pr($this->data); 
             if ($this->Carrier->save($this->request->data)) {

                $this->Session->setFlash(__('Your Details has been saved.'));
                 return $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('Unable to add your Details'));
            }
            }
        }

}
?>

查看/运营商/ index.php的

<h1>welcome to Carriers</h1>
<br />
<br/>
<?php echo $this->Form->create('Carrier', array('enctype' => 'multipart/form-data'));?>
<table>
<tr><h3>Register here</h3></tr>

<tr><td>F.Name</td><td><?php echo $this->Form->text('fname'); ?></td></tr>
<tr><td>L.Name</td><td><?php echo $this->Form->text('lname');?></td></tr>
<tr><td>Date Of Birth</td><td><?php echo $this->Form->date('dob');?></td></tr>
<tr><td>Degree</td><td><?php echo $this->Form->select('field', array('options' => array('B.E','B.sc','Mca','Mtech','Mba'))); ?></td></tr>
<tr><td>Sex</td><td><?php
$options=array('M'=>'Male','F'=>'Female');
$attributes=array('legend'=>false);
echo $this->Form->radio('gender',$options,$attributes);
?></td></tr>
<tr><td><?php echo $this->Form->input('Carrier.Resume', array('between'=>'<br />','type'=>'file'));?></td></tr>

<tr><td><?php echo $this->Form->end('Apply');?></td></tr>



</table>

我收到错误

数据库错误 错误:SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'数组' SQL查询:INSERT INTO cake_php_demo1carrierfnamelnamedobfieldgender,{{1 VALUES('Thulasiram','Papa','2014-03-25','1','M',数组)

2 个答案:

答案 0 :(得分:0)

您正在使用$this->data['Carrier']['Resume'] = $filename;这是正确的,但您正在调用$this->request->data上的保存。

所以你应该把它改成

// Set the file-name only to save in the database
$this->request->data['Carrier']['Resume'] = $filename;
pr($this->data);
if ($this->Carrier->save($this->request->data)) {
   // ...
}

答案 1 :(得分:0)

我认为$this->request->data['Carrier']['Resume']是一个数组(在您的代码的前面引用了$this->request->data['Carrier']['Resume']['tmp_name']$this->request->data['Carrier']['Resume']['name']),所以在分配$之前你可能需要unset它文件名到它。尝试:

// Set the file-name only to save in the database
unset($this->request->data['Carrier']['Resume']);
$this->request->data['Carrier']['Resume'] = $filename;