2011-10-10 41 views
0

我正在開發一個symfony項目,並且我開發了一個表單來上傳文件並將其信息保存到我的模型中的表中。並沒有使用sfForm類來實現我的表單。 這裏有我的形式Symfony:沒有sfForm對象的表單域訪問

<form name="new_file" action="<?php echo url_for('home/uploadFile');?>" method="post"> 
    <input type="file" id="file"> 
    <input value="<?php echo $codigo_maestro?>" id="master_id"> 
    <input value="<?php echo $codigo_entidad?>" id="entity_id"> 
    <input type="submit" value="Upload"> 
</form> 

所以現在我試圖訪問sumbited表單的字段在我的動作功能,不知道這個代碼是如何:(

$request->getParameter('file'); 
$request->getParameter('master_id'); 
$request->getParameter('entity_id'); 

沒」將不起作用。 所以請幫我解決這個!如何訪問我的表單字段從動作?

+1

您應該使用表單框架。這不是你應該怎麼做symfony中的表格。 – Flukey

回答

0

你需要一個名字添加到您的表單域,這是你可以通過訪問他們的名字$request->getParameter()

+0

不錯,工作,但現在,在文件輸入中,我需要訪問文件參數,如'名稱''大小''類型'...我該怎麼做? –

+0

'$ request-> getFiles()' – Maerlyn

0

最後我做到這樣,也許不是最優雅,但工作

in action.class.php 
    $file= $_FILES['file']; 
    $filesize = $archivo['size']; 
    $filetype = $archivo['type']; 
    $filename = str_replace(' ','-',$file['name']); 
相關問題