编辑视图上的cakephp2.X验证

编辑视图上的cakephp2.X验证,php,html,cakephp,file-upload,Php,Html,Cakephp,File Upload,当我创建项目时,图像上传验证工作正常,但当我编辑项目时,它总是要求我再次上传文件。使用firebug,我检查了img_上传输入,它的值为“Lighthouse.jpg” 我怎样才能克服这个问题 下面是我的模型验证 'img_upload' = array( 'extension' => array( 'rule' => array('extension', array('png','jpg','jpeg')),

当我创建项目时,图像上传验证工作正常,但当我编辑项目时,它总是要求我再次上传文件。使用firebug,我检查了img_上传输入,它的值为“Lighthouse.jpg”

我怎样才能克服这个问题

下面是我的模型验证

     'img_upload' = array(
         'extension' => array(
           'rule' => array('extension', array('png','jpg','jpeg')),
           'message' => "Only png,jpg,jpeg Files Allowed",
         )
      );
下面是我的html代码:

echo $this->Form->create('Project',array('type'=>'file'));
echo $this->Form->input('img_upload'); 
echo $this->Form->end('Submit');

您当前的规则使文件上载成为必填字段,因此,如果文件未在编辑时上载,则会出错。尝试将
'allowEmpty'=>true
添加到您的验证规则中,以防止需要它:-

 'img_upload' = array(
     'extension' => array(
         'rule' => array('extension', array('png','jpg','jpeg')),
         'message' => "Only png,jpg,jpeg Files Allowed",
         'allowEmpty' => true,
     ) 
 );

嗨,请尝试从更改输入代码

echo $this->Form->input('img_upload'); 
对此

echo $this->Form->input('img_upload','type'=>'file'); 

此验证规则可用于文件类型输入。