0

这是我的问题:我正在尝试在 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在浏览器窗口中看到它(如预期的那样),但在放回它们并刷新之后,它只执行一次,做它应该做的事情,并在下一次尝试时再次做同样的事情。说真的……什么鬼?我为此狂怒了一个多小时,我即将粉碎半径 75 英里范围内所有可粉碎的东西。以前有人处理过这个吗?

4

1 回答 1

0

所以我再一次回答我自己的问题。我真的应该停止麻烦问了。

看来,由于一个泛银河的愚蠢巧合,验证器类文件的名称与其他文件或类似文件发生冲突。重命名验证器类文件解决了这个问题。

于 2012-09-25T20:46:15.330 回答