<?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文件SQLSTATE [42S22]:列未找到:1054未知列在 '字段列表'
<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'字段列表'中的未知列'Array' SQL查詢:INSERT INTO cake_php_demo1
。 carrier
(fname
,lname
,dob
,field
,gender
,Resume
)VALUES( 'Thulasiram', '爸爸', '2014年3月25日', '1', 'M',陣列)
爲什麼不簡單地使用Cake Uploader來解決這個問題?它會處理上傳並保存到數據庫爲你。 – skywalker