CONTROLLER
class ImagesController extends AppController {
var $name = 'Images';
var $uses = array('Image','Person');
var $helpers = array('Html', 'Form');
function add($idp = 0, $mac = 0)
{
if (!empty($this->data) &&
is_uploaded_file($this->data['Image']['File']['tmp_name'])) {
$fileData = fread(fopen($this->data['Image']['File']['tmp_name'], "r"),
$this->data['Image']['File']['size']);
$this->data['Image']['name'] = $this->data['Image']['File']['name'];
$this->data['Image']['type'] = $this->data['Image']['File']['type'];
$this->data['Image']['size'] = $this->data['Image']['File']['size'];
$this->data['Image']['data'] = $fileData;
$this->data['Image']['people_id'] = $idp;
$this->Image->save($this->data);
$this->redirect(array('controller' => 'People', 'action' => 'welcome',$mac));
}
}
当我验证表单时,我丢失了两个参数$ idp和$ mac ..如何让它们持久存在?
查看
<?php
echo $form->create('Image', array('action' => 'add', 'type' => 'file'));
echo $form->file('File');
echo $form->submit('Upload');
echo $form->end();
?>
答案 0 :(得分:1)
您应该在表单元素中添加以下内容:
'url'=>$this->Html->url()
因此表单如下:
echo $form->create('Image', array('type' => 'file', 'url'=>$this->Html->url()));
基本上$ this-&gt; Html-&gt; url()获取带参数的当前url并将其传递给表单的操作,如果你提交相同的操作(通常如此),这应该保持你的参数很明智。
HTH