Kohana ORM和文件上传问题...当没有图像时,将记录徽标设置为等于记录徽标

时间:2011-07-20 17:02:16

标签: php kohana kohana-3 kohana-orm

这会导致此错误......

  

操作数应包含1列[UPDATE record SET logo =('',   '','',4,0)WHERE id ='0']

if ($_FILES['logo']['name'] == '') {
    $record->logo = $record->logo;
}
else{
    // INSERTION WORKS FINE
}

如果有所作为,我也会使用Formo模块......

有没有办法完全从插入脚本中删除徽标,或者这样......因为$record->logo = $record->logo会导致失败?

1 个答案:

答案 0 :(得分:0)

$record->logo = $record->logo;

如果未设置$ record->徽标会导致错误..您必须至少说:

$record->logo = '';

但最好的办法是使用Validation::factory($_FILES)->check()

if ( $logo->check() ) {
  // do your insert here
}

这只是我上次管理时的片段:

    $logo = Validation::factory($_FILES);
    $logo->rule('logo', 'Upload::not_empty')->rule('logo', 'Upload::type', array(':value', array('jpg', 'png', 'gif')));
    if ( $logo->check() ) {
      $logo = Upload::save($_FILES['logo'], NULL, 'assets/uploads/logo');
      $image = ORM::factory('image')->where('id', '=', $id)->where('type', '=', 'logo')->find();
      $path = explode('/', $logo);
      $path = end($path);
      $image->path = 'assets/uploads/logo/' . $path;
      $image->playlist_id = $id;
      $image->type = 'logo';
      $image->save();
    }