2
我想用jshelper製作上傳文件。在CakePHP 2.2.1中使用jshelper上傳文件
筆者認爲:
<?php echo $this->Form->create('Form', array(
'inputDefaults' => array(
'format' => array('before', 'error', 'label', 'between', 'input', 'after'),),
'enctype' => 'multipart/form-data'
));
echo $this->Form->input('Form.file', array('type' => 'file', 'id'=>'file'));
$this->Js->get('#file')->event(
'update',
$this->Js->request(
array('controller' => 'ControllerForm','action' => 'actionForm'),
array(
'async' => true,
'method' => 'post',
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'isForm' => false,
'inline' => true,
))
)
));
echo $this->Js->writeBuffer();
echo $this->Form->end();
?>
在我的控制器:
public function actionForm(){
debugger::dump($this->data);
}
但是debugger::dump
輸出空數組。
調試思路:您是否在瀏覽器控制檯中收到任何JS錯誤? CakePHP生成的JS的外觀如何?請求是否實際發送?請求主體包含什麼內容? –
不直接回答你的問題,但CakePHP上傳插件可能是一種更簡單的方法來實現相同的功能 – baordog