繁体   English   中英

PHP Symfony 1.4自定义验证器错误

[英]php symfony 1.4 custom validator error

这是我的问题:我正在尝试在symfony中编写一个自定义验证器。

用法:

$this->setValidator('path', new sfValidatorFile(array(

    'required'   => false,
    'path'       => sfConfig::get('sf_upload_dir'),
    'mime_types' => 'web_images',
    'validated_file_class' => 'sfImageTransform')));
}

验证器 :

<?php class sfImageTransform extends sfValidatedFile{

  public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777) {


   $saved = parent::save($file, $fileMode, $create, $dirMode);

       $img = new sfImage(sfConfig::get('sf_upload_dir').'/'.$saved, 'image/jpeg');
       $img->resize(500,400);
       $img->save();

       return $saved;
  }
} ?>

我收到此错误: Fatal error: Class 'sfImageTransform' not found in /http/htdocs/pizza_propel/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 167

这是让我谋杀我会遇到的第一位Sensio Lab员工的部分:每当我从验证程序文件中删除<?php ?>括号时,我都会得到此类class sfImageTransform extends sfValidatedFile{ public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777) { // let the parent class save the file and do what it normally does $saved = parent::save($file, $fileMode, $create, $dirMode); //echo $saved;die; $img = new sfImage(sfConfig::get('sf_upload_dir').'/'.$saved, 'image/jpeg'); $img->resize(500,400); $img->save(); //$saved->resize(1000,null); // //$saved->resize(1000,null)->overlay(new sfImage('logo.png'), 'bottom-right'); return $saved; } } Fatal error: Class 'sfImageTransform' not found in /http/htdocs/pizza_propel/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 167 class sfImageTransform extends sfValidatedFile{ public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777) { // let the parent class save the file and do what it normally does $saved = parent::save($file, $fileMode, $create, $dirMode); //echo $saved;die; $img = new sfImage(sfConfig::get('sf_upload_dir').'/'.$saved, 'image/jpeg'); $img->resize(500,400); $img->save(); //$saved->resize(1000,null); // //$saved->resize(1000,null)->overlay(new sfImage('logo.png'), 'bottom-right'); return $saved; } } Fatal error: Class 'sfImageTransform' not found in /http/htdocs/pizza_propel/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 167 class sfImageTransform extends sfValidatedFile{ public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777) { // let the parent class save the file and do what it normally does $saved = parent::save($file, $fileMode, $create, $dirMode); //echo $saved;die; $img = new sfImage(sfConfig::get('sf_upload_dir').'/'.$saved, 'image/jpeg'); $img->resize(500,400); $img->save(); //$saved->resize(1000,null); // //$saved->resize(1000,null)->overlay(new sfImage('logo.png'), 'bottom-right'); return $saved; } } Fatal error: Class 'sfImageTransform' not found in /http/htdocs/pizza_propel/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 167在浏览器窗口中class sfImageTransform extends sfValidatedFile{ public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777) { // let the parent class save the file and do what it normally does $saved = parent::save($file, $fileMode, $create, $dirMode); //echo $saved;die; $img = new sfImage(sfConfig::get('sf_upload_dir').'/'.$saved, 'image/jpeg'); $img->resize(500,400); $img->save(); //$saved->resize(1000,null); // //$saved->resize(1000,null)->overlay(new sfImage('logo.png'), 'bottom-right'); return $saved; } } Fatal error: Class 'sfImageTransform' not found in /http/htdocs/pizza_propel/lib/vendor/symfony/lib/validator/sfValidatorFile.class.php on line 167 ,(按预期),但是放置后它们返回并刷新,它完全执行一次,执行应做的事情,然后在下次尝试时再次执行相同的操作。 认真...到底是什么? 我为此花了一个多小时的时间,打算将75英里半径范围内的所有可粉碎物体粉碎。 有人处理过吗?

因此,我再次回答了自己的问题。 我真的应该停止打扰了。

看起来,由于语法上的愚蠢巧合,验证器类文件的名称与其他文件或类似文件发生冲突。 重命名验证器类文件解决了该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM